Submission #00051


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
char shop[22][22];
int W_root[4]={-1,0,1,0};
int H_root[4]={0,1,0,-1};
int W,H;
int w,h;
int ans=0;
int kouhun=0;
void dfs(int w ,int h){
shop[h][w] = '@';
ans++;
kouhun += ans*2;
for(int i=0;i<4;i++){
int smp1 = w+W_root[i];
int smp2 = h+H_root[i];
if(0<=smp1 && smp1<W && 0<=smp2 && smp2<H && shop[smp2][smp1]=='.'){
dfs(smp1,smp2);
}
}
return;
}
int main(){
while(1){
ans=0;
kouhun=0;
cin >> W >> H;
if(W == 0,H == 0)break;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin >> shop[i][j];
if(shop[i][j] == 'S'){
w = j;
h = i;
}
}
}
dfs(w,h);
cout << ans << endl << kouhun << endl;
}
}

ステータス

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

セット

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

テストケース

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