Submission #1049530

# Submission time Handle Problem Language Result Execution time Memory
1049530 2024-08-08T20:56:17 Z inkvizytor Tracks in the Snow (BOI13_tracks) C++17
86.875 / 100
1529 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<string> s (h);
    cin >> s[0] >> s[1];
    vector<vector<pair<int, bool>>> g (h*w);
    for (int i = 0; i < h; i++) {
        if (i < h-2) {
            cin >> s[i+2];
        }
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') continue;
            if (i != 0 && s[i-1][j] != '.') {
                g[i*w+j].push_back({(i-1)*w+j, s[i][j]==s[i-1][j]});
            }
            if (j != 0 && s[i][j-1] != '.') {
                g[i*w+j].push_back({i*w+j-1, s[i][j]==s[i][j-1]});
            }
            if (i != h-1 && s[i+1][j] != '.') {
                g[i*w+j].push_back({(i+1)*w+j, s[i][j]==s[i+1][j]});
            }
            if (j != w-1 && s[i][j+1] != '.') {
                g[i*w+j].push_back({i*w+j+1, s[i][j]==s[i][j+1]});
            }
        }
        if (i > 0) {
            s[i-1] = "";
        }
    }
    deque<pair<int, int>> q;
    vector<bool> odw (h*w, 0);
    q.push_back({0, 1});
    int maxd = 0;
    while (!q.empty()) {
        auto x = q.front();
        q.pop_front();
        if (odw[x.first]) {
            continue;
        }
        maxd = max(maxd, x.second);
        odw[x.first] = 1;
        for (auto i : g[x.first]) {
            if (odw[i.first]) continue;
            if (i.second) {
                q.push_front({i.first, x.second});
            }
            else {
                q.push_back({i.first, x.second+1});
            }
        }
    }
    cout << maxd << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 17500 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 20 ms 11844 KB Output is correct
5 Correct 3 ms 3164 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 3 ms 3164 KB Output is correct
11 Correct 4 ms 3260 KB Output is correct
12 Correct 12 ms 6492 KB Output is correct
13 Correct 3 ms 3232 KB Output is correct
14 Correct 3 ms 3164 KB Output is correct
15 Correct 25 ms 14940 KB Output is correct
16 Correct 27 ms 17500 KB Output is correct
17 Correct 13 ms 10840 KB Output is correct
18 Correct 15 ms 11728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2140 KB Output is correct
2 Correct 79 ms 67156 KB Output is correct
3 Correct 443 ms 548948 KB Output is correct
4 Correct 119 ms 113204 KB Output is correct
5 Correct 343 ms 363500 KB Output is correct
6 Runtime error 976 ms 1048576 KB Execution killed with signal 9
7 Correct 2 ms 1884 KB Output is correct
8 Correct 2 ms 2008 KB Output is correct
9 Correct 3 ms 3056 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 80 ms 67332 KB Output is correct
14 Correct 45 ms 39048 KB Output is correct
15 Correct 27 ms 33884 KB Output is correct
16 Correct 42 ms 31852 KB Output is correct
17 Correct 216 ms 171604 KB Output is correct
18 Correct 119 ms 133748 KB Output is correct
19 Correct 113 ms 113456 KB Output is correct
20 Correct 86 ms 121332 KB Output is correct
21 Correct 246 ms 321660 KB Output is correct
22 Correct 344 ms 363344 KB Output is correct
23 Correct 431 ms 332976 KB Output is correct
24 Correct 261 ms 318804 KB Output is correct
25 Correct 609 ms 538732 KB Output is correct
26 Correct 1137 ms 978620 KB Output is correct
27 Runtime error 956 ms 1048576 KB Execution killed with signal 9
28 Runtime error 988 ms 1048576 KB Execution killed with signal 9
29 Runtime error 949 ms 1048576 KB Execution killed with signal 9
30 Runtime error 985 ms 1048576 KB Execution killed with signal 9
31 Correct 1529 ms 733468 KB Output is correct
32 Runtime error 1004 ms 1048576 KB Execution killed with signal 9