Submission #839797

# Submission time Handle Problem Language Result Execution time Memory
839797 2023-08-30T16:13:13 Z Kavelmydex Tracks in the Snow (BOI13_tracks) C++17
100 / 100
663 ms 180704 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef vector <ll> vi;
typedef pair <ll,ll> pi;
#define f first
#define s second

int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
string grid[4000];
int depth[4000][4000], ans = 1;
int n, m;

bool inside(int x, int y){
    return x >= 0 && y >= 0 && x < n && y < m && grid[x][y] != '.';
}

int main() {
    //ios::sync_with_stdio(0); cin.tie(0);
    //freopen("guard.in", "r", stdin);
    //freopen("guard.out", "w", stdout);

    cin >> n >> m;
    for(int i=0; i<n; i++){
        cin >> grid[i];
    }

    deque <pi> q;
    q.push_back({0, 0});
    depth[0][0] = 1;
    while(q.size()){
        int u = q.front().f, v = q.front().s;
        ans = max(ans, depth[u][v]);
        q.pop_front();
        for(int i=0; i<4; i++){
            int x = u + dx[i], y = v + dy[i];
            if(!inside(x, y) || depth[x][y] != 0) continue;

            if(grid[u][v] == grid[x][y]){
                depth[x][y] = depth[u][v];
                q.push_front({x, y});
            }else{
                depth[x][y] = depth[u][v] + 1;
                q.push_back({x, y});
            }
        }
    }
    cout << ans;
    return 0;
}   
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4096 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 7 ms 3668 KB Output is correct
5 Correct 3 ms 2004 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 3 ms 1620 KB Output is correct
11 Correct 2 ms 1492 KB Output is correct
12 Correct 5 ms 2168 KB Output is correct
13 Correct 3 ms 1980 KB Output is correct
14 Correct 3 ms 2016 KB Output is correct
15 Correct 12 ms 3924 KB Output is correct
16 Correct 12 ms 4120 KB Output is correct
17 Correct 10 ms 3900 KB Output is correct
18 Correct 7 ms 3668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15828 KB Output is correct
2 Correct 48 ms 12620 KB Output is correct
3 Correct 340 ms 87772 KB Output is correct
4 Correct 94 ms 32464 KB Output is correct
5 Correct 233 ms 53160 KB Output is correct
6 Correct 663 ms 135940 KB Output is correct
7 Correct 12 ms 16468 KB Output is correct
8 Correct 9 ms 15800 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 9 ms 16212 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 49 ms 12608 KB Output is correct
14 Correct 29 ms 8816 KB Output is correct
15 Correct 26 ms 11088 KB Output is correct
16 Correct 22 ms 5040 KB Output is correct
17 Correct 123 ms 28548 KB Output is correct
18 Correct 107 ms 35400 KB Output is correct
19 Correct 95 ms 32432 KB Output is correct
20 Correct 78 ms 25356 KB Output is correct
21 Correct 204 ms 52236 KB Output is correct
22 Correct 260 ms 53200 KB Output is correct
23 Correct 234 ms 43424 KB Output is correct
24 Correct 204 ms 49340 KB Output is correct
25 Correct 550 ms 108748 KB Output is correct
26 Correct 430 ms 180704 KB Output is correct
27 Correct 549 ms 162024 KB Output is correct
28 Correct 653 ms 135904 KB Output is correct
29 Correct 658 ms 132732 KB Output is correct
30 Correct 601 ms 142372 KB Output is correct
31 Correct 474 ms 73420 KB Output is correct
32 Correct 496 ms 134052 KB Output is correct