Submission #00018


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int w,h;
char memo[50][50];
int B=0;
int A=0;
void dfs(int x,int y){
if(memo[y][x]=='@') return ;
if(x<0 || y<0 || x>=w || y>=h) return ;
memo[y][x]='@';
A++;
B+=(A*2);
dfs(x-1,y);
dfs(x+1,y);
dfs(x,y-1);
dfs(x,y+1);
return ;
}
int main(){
while(1){
int x=0,y=0;
scanf("%d %d",&w,&h);
if(w==0 && h==0) break;
for(int i=0;i<h;i++){
scanf("%s",memo[i]);
for(int j=0;j<w;j++){
if(memo[i][j]=='S'){
x=j;
y=i;
}
}
}
dfs(x,y);
printf("%d\n%d\n",A,B);
A=0;
B=0;
}
return 0;
}

ステータス

項目 データ
問題 0001 - もりたのクッキー☆kiss
ユーザー名 ei1410
投稿日時 2015-09-16 17:03:31
言語 C++11
状態 Accepted
得点 100
ソースコード長 715 Byte
最大実行時間 25 ms
最大メモリ使用量 708 KB

セット

セット 得点 Cases
1 ALL 100 / 100 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
DFS_in1.txt AC 21 ms 476 KB
1
DFS_in2.txt AC 19 ms 708 KB
1
DFS_in3.txt AC 25 ms 564 KB
1