Submission #351298

# Submission time Handle Problem Language Result Execution time Memory
351298 2021-01-19T21:51:45 Z eyangch Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1142 ms 410512 KB
#include <bits/stdc++.h>

using namespace std;

struct s{
    int x, y, d;
};
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int H, W;
string m[4000];
bool vis[4000][4000];

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        cin >> m[i];
    }
    deque<s> q;
    q.push_back({0, 0, 1});
    int ans = 0;
    while(!q.empty()){
        s cur = q.front();
        q.pop_front();
        int x = cur.x, y = cur.y, d = cur.d;
        if(vis[x][y]) continue;
        vis[x][y] = true;
        ans = max(ans, d);
        for(int i = 0; i < 4; i++){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || ny < 0 || nx >= H || ny >= W || m[nx][ny] == '.') continue;
            if(m[x][y] != m[nx][ny]){
                q.push_back({nx, ny, d+1});
            }else{
                q.push_front({nx, ny, d});
            }
        }
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3200 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 11 ms 3308 KB Output is correct
5 Correct 3 ms 1772 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 3 ms 1644 KB Output is correct
11 Correct 3 ms 1516 KB Output is correct
12 Correct 8 ms 2028 KB Output is correct
13 Correct 3 ms 1772 KB Output is correct
14 Correct 3 ms 1772 KB Output is correct
15 Correct 16 ms 3052 KB Output is correct
16 Correct 20 ms 3180 KB Output is correct
17 Correct 11 ms 2924 KB Output is correct
18 Correct 11 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 15596 KB Output is correct
2 Correct 52 ms 8556 KB Output is correct
3 Correct 250 ms 49516 KB Output is correct
4 Correct 65 ms 15548 KB Output is correct
5 Correct 190 ms 30700 KB Output is correct
6 Correct 1049 ms 100508 KB Output is correct
7 Correct 13 ms 16236 KB Output is correct
8 Correct 12 ms 15468 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 13 ms 15852 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 52 ms 8556 KB Output is correct
14 Correct 31 ms 5996 KB Output is correct
15 Correct 18 ms 6380 KB Output is correct
16 Correct 27 ms 3436 KB Output is correct
17 Correct 135 ms 16748 KB Output is correct
18 Correct 75 ms 16620 KB Output is correct
19 Correct 62 ms 15468 KB Output is correct
20 Correct 62 ms 14336 KB Output is correct
21 Correct 151 ms 31724 KB Output is correct
22 Correct 193 ms 30700 KB Output is correct
23 Correct 269 ms 26476 KB Output is correct
24 Correct 141 ms 31340 KB Output is correct
25 Correct 389 ms 49516 KB Output is correct
26 Correct 1142 ms 410512 KB Output is correct
27 Correct 1020 ms 187812 KB Output is correct
28 Correct 1070 ms 100556 KB Output is correct
29 Correct 1018 ms 96956 KB Output is correct
30 Correct 1047 ms 123192 KB Output is correct
31 Correct 939 ms 36812 KB Output is correct
32 Correct 1055 ms 169552 KB Output is correct