Submission #00125
ソースコード
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; char maps[1001][1001]; bool check[1001][1001]; int dx[4] = {0,0,1,-1}; int dy[4] = {1,-1,0,0}; int h,w,n,sx,sy; struct s{ int y,x,num,ans; }; int main(){ cin >> h >> w >> n; for ( int i=0;i<h;i++){ for ( int j=0;j<w;j++){ cin >> maps[i][j]; if (maps[i][j] == 'S' ){ sx = j; sy = i; } } } queue<s> q; q.push((s){sy,sx,1,0}); while (!q.empty()){ s f = q.front();q.pop(); if (f.x >= w || f.x < 0 || f.y >=h || f.y < 0 || maps[f.y][f.x] == 'X' || check[f.y][f.x] == true ){ continue ; } check[f.y][f.x] = true ; if (f.num-1 == n){ cout << f.ans-1 << endl; break ; } f.ans++; if (maps[f.y][f.x]== char ( '0' +f.num)){ for ( int i=0;i<h;i++){ for ( int j=0;j<w;j++){ check[i][j] = false ; } } while (!q.empty())q.pop(); f.num++; } for ( int i=0;i<4;i++){ q.push((s){f.y+dy[i],f.x+dx[i],f.num,f.ans}); } } } |
ステータス
項目 | データ |
---|---|
問題 | 0005 - チーズ(Cheese) |
ユーザー名 | ei1506 |
投稿日時 | 2016-11-09 18:38:02 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 1017 Byte |
最大実行時間 | 143 ms |
最大メモリ使用量 | 2520 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | in1 | 20 / 20 | in1.txt |
2 | in2 | 20 / 20 | in2.txt |
3 | in3 | 20 / 20 | in3.txt |
4 | in4 | 20 / 20 | in4.txt |
5 | in5 | 20 / 20 | in5.txt |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||||
---|---|---|---|---|---|---|---|---|
in1.txt | AC | 23 ms | 476 KB |
1
|
||||
in2.txt | AC | 24 ms | 576 KB |
2
|
||||
in3.txt | AC | 27 ms | 644 KB |
3
|
||||
in4.txt | AC | 143 ms | 2256 KB |
4
|
||||
in5.txt | AC | 88 ms | 2520 KB |
5
|