Submission #00004
ソースコード
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 55 56 57 58 59 60 61 | #include <map> #include <set> #include <cmath> #include <queue> #include <stack> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <cstdlib> #include <cstring> #include <sstream> #include <iostream> #include <algorithm> #include <functional> #define INF (2 << 28) #define fr first #define sc second using namespace std; typedef long long ll; typedef pair< int , int > iP; int W, H; char mas[21][21]; int dfs( int x, int y) { int ret = 1; mas[y][x] = '@' ; static int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 }; for ( int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (0 <= nx && nx < W && 0 <= ny && ny < H && mas[ny][nx] != '@' ) { ret += dfs(nx, ny); } } return ret; } int main(){ while (cin >> W >> H, W||H) { int sx, sy; 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; } } int res = 0; int an = dfs(sx, sy); for ( int i = 1; i <= an; i++) { res += i * 2; } cout << an << endl; cout << res << endl; } } |
ステータス
項目 | データ |
---|---|
問題 | 0001 - もりたのクッキー☆kiss |
ユーザー名 | Jogasaki_Mika_Tanto_P |
投稿日時 | 2015-09-16 16:47:23 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 1188 Byte |
最大実行時間 | 20 ms |
最大メモリ使用量 | 712 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 100 / 100 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
DFS_in1.txt | AC | 19 ms | 476 KB |
1
|
DFS_in2.txt | AC | 19 ms | 712 KB |
1
|
DFS_in3.txt | AC | 20 ms | 564 KB |
1
|