# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101457 | 2019-03-19T02:35:54 Z | rocketninja7 | Tracks in the Snow (BOI13_tracks) | C++14 | 1643 ms | 88968 KB |
#include <cstdio> #include <vector> #include <queue> #include <algorithm> using namespace std; pair<int, int> dir[]={make_pair(0, -1), make_pair(1, 0), make_pair(0, 1), make_pair(-1, 0)}; int main(){ int H, W; scanf("%d%d", &H, &W); char grid[H][W+1]; for(int i=0;i<H;i++){ scanf("%s", &grid[i]); } int dist[H][W]; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ dist[i][j]=-1; } } dist[0][0]=1; queue<pair<int, int> > procA; queue<pair<int, int> > procB; procA.push(make_pair(0, 0)); while(!procA.empty()||!procB.empty()){ while(!procA.empty()){ int x=procA.front().first, y=procA.front().second; procA.pop(); for(int i=0;i<4;i++){ if(x+dir[i].first>-1&&x+dir[i].first<H&&y+dir[i].second>-1&&y+dir[i].second<W){ if(grid[x+dir[i].first][y+dir[i].second]!='.'){ if(dist[x+dir[i].first][y+dir[i].second]==-1){ if(grid[x+dir[i].first][y+dir[i].second]==grid[x][y]){ dist[x+dir[i].first][y+dir[i].second]=dist[x][y]; procA.push(make_pair(x+dir[i].first, y+dir[i].second)); } else{ dist[x+dir[i].first][y+dir[i].second]=dist[x][y]+1; procB.push(make_pair(x+dir[i].first, y+dir[i].second)); } } } } } } while(!procB.empty()){ int x=procB.front().first, y=procB.front().second; procB.pop(); for(int i=0;i<4;i++){ if(x+dir[i].first>-1&&x+dir[i].first<H&&y+dir[i].second>-1&&y+dir[i].second<W){ if(grid[x+dir[i].first][y+dir[i].second]!='.'){ if(dist[x+dir[i].first][y+dir[i].second]==-1){ if(grid[x+dir[i].first][y+dir[i].second]==grid[x][y]){ dist[x+dir[i].first][y+dir[i].second]=dist[x][y]; procB.push(make_pair(x+dir[i].first, y+dir[i].second)); } else{ dist[x+dir[i].first][y+dir[i].second]=dist[x][y]+1; procA.push(make_pair(x+dir[i].first, y+dir[i].second)); } } } } } } } int ans=1; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ ans=max(ans, dist[i][j]); } } printf("%d", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 1536 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 8 ms | 1152 KB | Output is correct |
5 | Correct | 3 ms | 768 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 640 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 7 ms | 768 KB | Output is correct |
13 | Correct | 5 ms | 768 KB | Output is correct |
14 | Correct | 4 ms | 768 KB | Output is correct |
15 | Correct | 15 ms | 1536 KB | Output is correct |
16 | Correct | 16 ms | 1536 KB | Output is correct |
17 | Correct | 14 ms | 1536 KB | Output is correct |
18 | Correct | 11 ms | 1152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 640 KB | Output is correct |
2 | Correct | 55 ms | 8016 KB | Output is correct |
3 | Correct | 346 ms | 78632 KB | Output is correct |
4 | Correct | 86 ms | 18684 KB | Output is correct |
5 | Correct | 204 ms | 44368 KB | Output is correct |
6 | Correct | 1387 ms | 88840 KB | Output is correct |
7 | Correct | 3 ms | 512 KB | Output is correct |
8 | Correct | 3 ms | 512 KB | Output is correct |
9 | Correct | 4 ms | 640 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 3 ms | 512 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 49 ms | 7936 KB | Output is correct |
14 | Correct | 32 ms | 4736 KB | Output is correct |
15 | Correct | 26 ms | 5248 KB | Output is correct |
16 | Correct | 29 ms | 3456 KB | Output is correct |
17 | Correct | 148 ms | 20244 KB | Output is correct |
18 | Correct | 133 ms | 19836 KB | Output is correct |
19 | Correct | 91 ms | 18812 KB | Output is correct |
20 | Correct | 67 ms | 17152 KB | Output is correct |
21 | Correct | 193 ms | 45916 KB | Output is correct |
22 | Correct | 166 ms | 44408 KB | Output is correct |
23 | Correct | 309 ms | 38392 KB | Output is correct |
24 | Correct | 167 ms | 44792 KB | Output is correct |
25 | Correct | 560 ms | 78560 KB | Output is correct |
26 | Correct | 647 ms | 60548 KB | Output is correct |
27 | Correct | 1054 ms | 80376 KB | Output is correct |
28 | Correct | 1643 ms | 88968 KB | Output is correct |
29 | Correct | 1340 ms | 87384 KB | Output is correct |
30 | Correct | 1312 ms | 84784 KB | Output is correct |
31 | Correct | 995 ms | 51084 KB | Output is correct |
32 | Correct | 857 ms | 79396 KB | Output is correct |