Submission #00007


ソースコード

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;
int W, H;
char ramenShop[21][21];
int DFS(int x, int y)
{
ramenShop[y][x] = '@';
const static int dx[] = {0, -1, 0, 1};
const static int dy[] = {1, 0, -1, 0};
int ret = 0;
for(int i = 0; i < 4; i++){
int nx = x + dx[i], ny = y + dy[i];
if(nx < 0 || W <= nx || ny < 0 || H <= ny || ramenShop[ny][nx] == '@') continue;
ret += DFS(nx, ny) + 1;
}
return ret;
}
int main()
{
while(cin >> W >> H, W || H){
int sx, sy;
memset(ramenShop, '\0', sizeof(ramenShop));
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
cin >> ramenShop[i][j];
if(ramenShop[i][j] == 'S') sx = j, sy = i;
}
}
int n = DFS(sx, sy) + 1;
int ans = 0;
for(int i = 1; i <= n; i++){
ans += i * 2;
}
cout << n << endl;
cout << ans << endl;
}
}

ステータス

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

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
DFS_in1.txt AC 22 ms 472 KB
1
DFS_in2.txt AC 21 ms 584 KB
1
DFS_in3.txt AC 24 ms 564 KB
1