Submission #00016


ソースコード

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
53
54
#include<iostream>
#include<cstdio>
#include<algorithm>
void saiki(int x,int y);
int w,h,ans,ex;
int i,j;
char map[21][21]={};
int main(){
while(1){
scanf("%d %d",&w,&h);
if(w==0 && h==0) break;
for(i=0;i<h;i++) scanf("%s",map[i]);
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(map[i][j]=='S') saiki(j,i);
}
}
printf("%d\n%d\n",ans,ex);
ans=0; ex=0;
}
return 0;
}
void saiki(int x,int y){
//今いる場所を鳴門とする
map[y][x]='@';
ans++;
ex+=ans*2;
//4方向を確認
int nx=x; int ny=y-1;
if(0<=nx && nx<w && 0<=ny && ny<h && map[ny][nx]=='.') saiki(nx,ny);
nx--; ny+=1;
if(0<=nx && nx<w && 0<=ny && ny<h && map[ny][nx]=='.') saiki(nx,ny);
nx+=2;
if(0<=nx && nx<w && 0<=ny && ny<h && map[ny][nx]=='.') saiki(nx,ny);
nx--; ny++;
if(0<=nx && nx<w && 0<=ny && ny<h && map[ny][nx]=='.') saiki(nx,ny);
//終わり
else return;
}

ステータス

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

セット

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

テストケース

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