Submission #00002


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
int h,w;
int sx,sy;
char mas[21][21];
int flg[21][21];
int dx[] = {0,-1,1,0};
int dy[] = {1,0,0,-1};
int ans = 0;
int cou = 0;
void dfs(int nowx,int nowy);
int main(){
while(1){
cin >> w >> h;
ans = 0;
cou = 0;
if(w == 0 && h == 0) break;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin >> mas[i][j];
if(mas[i][j] == 'S'){
sx = j;
sy = i;
}
flg[i][j] = 0;
}
}
dfs(sx,sy);
cout << cou << endl;
cout << ans << endl;
}
}
void dfs(int nowx,int nowy){
if(flg[nowy][nowx]) return;
cou++;
ans += cou*2;
flg[nowy][nowx]=1;
for(int i=0;i<4;i++){
int nx = nowx + dx[i];
int ny = nowy + dy[i];
if(nx >= 0 && ny >= 0 && nx < w && ny < h && mas[ny][nx] != '@'){
dfs(nx,ny);
}
}
return;
}

ステータス

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

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
DFS_in1.txt AC 27 ms 472 KB
1
DFS_in2.txt AC 15 ms 708 KB
1
DFS_in3.txt AC 16 ms 560 KB
1