Submission #00021
ソースコード
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 <iostream> using namespace std; void dfs( int x, int y); int n,m; int h,w; int a=0; int ans=0; int cnt=0; int d[111][111]; char maps[111][111]; int flag=0; int main(){ int sx,sy; while (1){ cin >> w >> h; if (w==0 && h==0) break ; for ( int i=0;i<h;i++){ for ( int j=0;j<w;j++){ cin >> maps[i][j]; d[i][j]=0; if (maps[i][j]== 'S' ){ sx=j; sy=i; } } } dfs(sx,sy); ans=ans+a*2; cout << cnt+1 << endl << ans << endl; ans=0; flag=0; a=0; cnt=0; } } void dfs( int x, int y){ int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; int nx,ny; for ( int i=0;i<4;i++){ nx=x+dx[i]; ny=y+dy[i]; if (nx>=0 && ny>=0 && nx<w && ny<h && d[ny][nx]!=1 && maps[ny][nx]!= '@' ){ if (maps[ny][nx]== '.' ){ if (flag==0){ //一番最初のキャンディをとる ans=2; a=2; cnt++; flag=1; } else { ans=ans+a*2; a++; cnt++; } d[ny][nx]=1; dfs(nx,ny); } } } } |
ステータス
項目 | データ |
---|---|
問題 | 0001 - もりたのクッキー☆kiss |
ユーザー名 | ei1435 |
投稿日時 | 2015-09-16 17:25:06 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 1007 Byte |
最大実行時間 | 22 ms |
最大メモリ使用量 | 700 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 100 / 100 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
DFS_in1.txt | AC | 22 ms | 476 KB |
1
|
DFS_in2.txt | AC | 15 ms | 700 KB |
1
|
DFS_in3.txt | AC | 22 ms | 660 KB |
1
|