Submission #867754

# Submission time Handle Problem Language Result Execution time Memory
867754 2023-10-29T12:22:52 Z BoopyTheNoob Tracks in the Snow (BOI13_tracks) C++14
97.8125 / 100
440 ms 133116 KB
#include <bits/stdc++.h>
using namespace std;

int main (void) {
    iostream::sync_with_stdio(false);
	cin.tie(0);
    int dx[4] = {0, 0, 1, -1};
    int dy[4] = {1, -1, 0, 0};
    int N, M;
    cin >> N >> M;
    //vector<string> grid(N);
    string grid[4000];
    for (int i = 0; i < N; i++)
        cin >> grid[i];
    //vector<vector<int>> dist(N, vector<int>(M, 0));
    int dist[4000][4000];
    deque<pair<int, int>> bfs;
    bfs.push_back({0, 0});
    dist[0][0] = 1;
    int ans = 0;
    while (!bfs.empty()) {
        int x = bfs.front().first, y = bfs.front().second;
        bfs.pop_front();
        ans = max(ans, dist[x][y]);
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= N || ny < 0 || ny >= M)
                continue;
            if (dist[nx][ny] != 0 || grid[nx][ny] == '.')
                continue;
            pair<int, int> next = {nx, ny};
            if (grid[x][y] != grid[nx][ny]) {
                dist[nx][ny] = dist[x][y] + 1;
                bfs.push_back({nx, ny});
            } else {
                dist[nx][ny] = dist[x][y];
                bfs.push_front({nx, ny});
            }
        }
    }
    /*for (auto x: dist) {
        for (auto y: x) {
            cout << y << " ";
        }
        cout << endl;
    }*/
    cout << ans << endl;
    return 0;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:31:28: warning: variable 'next' set but not used [-Wunused-but-set-variable]
   31 |             pair<int, int> next = {nx, ny};
      |                            ^~~~
# Verdict Execution time Memory Grader output
1 Correct 41 ms 63568 KB Output is correct
2 Correct 33 ms 63060 KB Output is correct
3 Correct 32 ms 63056 KB Output is correct
4 Correct 38 ms 63828 KB Output is correct
5 Correct 33 ms 63312 KB Output is correct
6 Correct 32 ms 63096 KB Output is correct
7 Correct 34 ms 62960 KB Output is correct
8 Correct 33 ms 63056 KB Output is correct
9 Correct 33 ms 62956 KB Output is correct
10 Correct 33 ms 63060 KB Output is correct
11 Correct 37 ms 63828 KB Output is correct
12 Correct 35 ms 63144 KB Output is correct
13 Correct 33 ms 63324 KB Output is correct
14 Correct 34 ms 63172 KB Output is correct
15 Correct 38 ms 63664 KB Output is correct
16 Correct 41 ms 63728 KB Output is correct
17 Correct 38 ms 63572 KB Output is correct
18 Correct 40 ms 63652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 63064 KB Output is correct
2 Correct 56 ms 65804 KB Output is correct
3 Correct 163 ms 89296 KB Output is correct
4 Correct 70 ms 69200 KB Output is correct
5 Correct 126 ms 77904 KB Output is correct
6 Correct 440 ms 102620 KB Output is correct
7 Correct 34 ms 63060 KB Output is correct
8 Correct 35 ms 63060 KB Output is correct
9 Correct 40 ms 63196 KB Output is correct
10 Correct 33 ms 63068 KB Output is correct
11 Correct 34 ms 63056 KB Output is correct
12 Correct 32 ms 63188 KB Output is correct
13 Correct 56 ms 65856 KB Output is correct
14 Correct 50 ms 64720 KB Output is correct
15 Correct 47 ms 64744 KB Output is correct
16 Correct 46 ms 64344 KB Output is correct
17 Correct 106 ms 70048 KB Output is correct
18 Correct 76 ms 69964 KB Output is correct
19 Correct 75 ms 69436 KB Output is correct
20 Correct 64 ms 68900 KB Output is correct
21 Correct 109 ms 78848 KB Output is correct
22 Correct 127 ms 78016 KB Output is correct
23 Correct 170 ms 75720 KB Output is correct
24 Correct 110 ms 77984 KB Output is correct
25 Incorrect 73 ms 89308 KB Output isn't correct
26 Correct 383 ms 133116 KB Output is correct
27 Correct 366 ms 107516 KB Output is correct
28 Correct 415 ms 102564 KB Output is correct
29 Correct 403 ms 99972 KB Output is correct
30 Correct 408 ms 105748 KB Output is correct
31 Correct 354 ms 80212 KB Output is correct
32 Correct 360 ms 105988 KB Output is correct