Submission #00006
ソースコード
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 | #include<bits/stdc++.h> using namespace std; int w, h; int sx, sy; char mp[20][20]; int nx[] = {1, 0, -1, 0}; int ny[] = {0, 1, 0, -1}; int dfs( int x, int y); int main(){ while (cin >> w >> h, w, h){ for ( int i = 0; i < h; i++){ for ( int j = 0; j < w; j++){ cin >> mp[i][j]; if (mp[i][j] == 'S' ){ sx = j; sy = i; } } } int ans = dfs(sx, sy); cout << ans << endl; int led = 0; for ( int i = 1; i <= ans; i++) led += i * 2; cout << led << endl; } } int dfs( int x, int y){ int n = 0; if (mp[y][x] = '.' ) n++; mp[y][x] = '@' ; for ( int i = 0; i < 4; i++){ int nextx = nx[i] + x; int nexty = ny[i] + y; if (nextx >= 0 && nexty >= 0 && nextx < w && nexty < h && mp[nexty][nextx] == '.' ) n += dfs(nextx, nexty); } return n; } |
ステータス
項目 | データ |
---|---|
問題 | 0001 - もりたのクッキー☆kiss |
ユーザー名 | ei1409 |
投稿日時 | 2015-09-16 16:51:00 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 836 Byte |
最大実行時間 | 21 ms |
最大メモリ使用量 | 568 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 100 / 100 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
DFS_in1.txt | AC | 19 ms | 476 KB |
1
|
DFS_in2.txt | AC | 16 ms | 460 KB |
1
|
DFS_in3.txt | AC | 21 ms | 568 KB |
1
|