# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
854113 | 2023-09-26T07:26:58 Z | nhatvpm | Tracks in the Snow (BOI13_tracks) | C++17 | 547 ms | 124000 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; void setIO(string name) { freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } void solve(){ int n,m,dx[]={0,0,1,-1},dy[]={1,-1,0,0}; cin>>n>>m; string grid[n]; for (int i=0;i<n;i++) cin>>grid[i]; deque<pair<int,int>> q; vector<vector<int>> dis(n,vector<int>(m,0)); dis[0][0]=1; int res=0; q.push_front({0,0}); while (!q.empty()){ int x=q.front().first,y=q.front().second; res=max(res,dis[x][y]); q.pop_front(); for (int i=0;i<4;i++){ int r=x+dx[i],c=y+dy[i]; if (r>=0&&r<n&&c>=0&&c<m&&grid[r][c]!='.'&&dis[r][c]==0){ int w=grid[r][c]!=grid[x][y]?1:0; dis[r][c]=dis[x][y]+w; if (w==1) q.push_back({r,c}); else q.push_front({r,c}); } } } cout<<res; } int main(){ //setIO(""); ios_base::sync_with_stdio(0); cin.tie(0); int tc=1; //cin>>tc; while (tc--){ solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 1880 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 4 ms | 1368 KB | Output is correct |
5 | Correct | 2 ms | 856 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 344 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 2 ms | 856 KB | Output is correct |
12 | Correct | 3 ms | 856 KB | Output is correct |
13 | Correct | 2 ms | 856 KB | Output is correct |
14 | Correct | 2 ms | 856 KB | Output is correct |
15 | Correct | 6 ms | 1880 KB | Output is correct |
16 | Correct | 8 ms | 1880 KB | Output is correct |
17 | Correct | 5 ms | 1880 KB | Output is correct |
18 | Correct | 4 ms | 1368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 856 KB | Output is correct |
2 | Correct | 25 ms | 9820 KB | Output is correct |
3 | Correct | 150 ms | 96760 KB | Output is correct |
4 | Correct | 39 ms | 22860 KB | Output is correct |
5 | Correct | 79 ms | 54352 KB | Output is correct |
6 | Correct | 515 ms | 109788 KB | Output is correct |
7 | Correct | 2 ms | 856 KB | Output is correct |
8 | Correct | 2 ms | 860 KB | Output is correct |
9 | Correct | 2 ms | 612 KB | Output is correct |
10 | Correct | 1 ms | 600 KB | Output is correct |
11 | Correct | 2 ms | 856 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
13 | Correct | 25 ms | 9816 KB | Output is correct |
14 | Correct | 14 ms | 5720 KB | Output is correct |
15 | Correct | 10 ms | 6232 KB | Output is correct |
16 | Correct | 13 ms | 4188 KB | Output is correct |
17 | Correct | 74 ms | 24704 KB | Output is correct |
18 | Correct | 44 ms | 24624 KB | Output is correct |
19 | Correct | 39 ms | 22604 KB | Output is correct |
20 | Correct | 34 ms | 21032 KB | Output is correct |
21 | Correct | 94 ms | 56236 KB | Output is correct |
22 | Correct | 83 ms | 54352 KB | Output is correct |
23 | Correct | 133 ms | 46832 KB | Output is correct |
24 | Correct | 85 ms | 54864 KB | Output is correct |
25 | Correct | 322 ms | 96484 KB | Output is correct |
26 | Correct | 531 ms | 124000 KB | Output is correct |
27 | Correct | 484 ms | 114876 KB | Output is correct |
28 | Correct | 547 ms | 109960 KB | Output is correct |
29 | Correct | 506 ms | 107436 KB | Output is correct |
30 | Correct | 514 ms | 111920 KB | Output is correct |
31 | Correct | 319 ms | 62016 KB | Output is correct |
32 | Correct | 476 ms | 113572 KB | Output is correct |