Submission #578092

# Submission time Handle Problem Language Result Execution time Memory
578092 2022-06-16T04:08:57 Z kliang Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1386 ms 117616 KB
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
    int h, w; cin >> h >> w;
    char meadow[h][w]; int depth[h][w];
    for(int y=0; y<h; ++y) {
        for(int x=0; x<w; ++x) {
            cin >> meadow[y][x];
            depth[y][x] = -1;
        }
    }
    int deltaY[4] = {-1, 0, 1, 0};
    int deltaX[4] = {0, 1, 0, -1};
    deque<pair<int, int> > bfs;
    pair<int, int> start; start.first = 0;
    start.second = 0; bfs.push_front(start);
    depth[0][0] = 1; int animals = 1;
    while(!bfs.empty()) {
        int y = bfs.front().first;
        int x = bfs.front().second;
        bfs.pop_front();
        animals = max(animals, depth[y][x]);
        for(int i=0; i<4; ++i) {
            pair<int, int> next;
            next.first = y + deltaY[i];
            next.second = x + deltaX[i];
            if(next.first >= 0 && next.first < h
            && next.second >= 0 && next.second < w
            && meadow[next.first][next.second] != '.'
            && depth[next.first][next.second] == -1) {
                if(meadow[y][x] == meadow[next.first][next.second]) {
                    depth[next.first][next.second] = depth[y][x];
                    bfs.push_front(next);
                }
                else {
                    depth[next.first][next.second] = depth[y][x] + 1;
                    bfs.push_back(next);
                }
            }
        }
    }
    cout << animals << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1748 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 13 ms 1364 KB Output is correct
5 Correct 6 ms 724 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 6 ms 668 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 8 ms 724 KB Output is correct
13 Correct 7 ms 724 KB Output is correct
14 Correct 6 ms 780 KB Output is correct
15 Correct 20 ms 1720 KB Output is correct
16 Correct 23 ms 1716 KB Output is correct
17 Correct 18 ms 1700 KB Output is correct
18 Correct 15 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 480 KB Output is correct
2 Correct 118 ms 9444 KB Output is correct
3 Correct 1044 ms 85536 KB Output is correct
4 Correct 245 ms 22180 KB Output is correct
5 Correct 603 ms 51216 KB Output is correct
6 Correct 1386 ms 100148 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 5 ms 564 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 119 ms 9440 KB Output is correct
14 Correct 66 ms 5576 KB Output is correct
15 Correct 68 ms 6132 KB Output is correct
16 Correct 51 ms 4040 KB Output is correct
17 Correct 292 ms 24072 KB Output is correct
18 Correct 264 ms 23664 KB Output is correct
19 Correct 254 ms 22184 KB Output is correct
20 Correct 228 ms 20408 KB Output is correct
21 Correct 603 ms 52788 KB Output is correct
22 Correct 603 ms 51276 KB Output is correct
23 Correct 569 ms 45088 KB Output is correct
24 Correct 593 ms 51784 KB Output is correct
25 Correct 1116 ms 85472 KB Output is correct
26 Correct 980 ms 117616 KB Output is correct
27 Correct 1297 ms 114824 KB Output is correct
28 Correct 1368 ms 100192 KB Output is correct
29 Correct 1367 ms 96208 KB Output is correct
30 Correct 1323 ms 103864 KB Output is correct
31 Correct 957 ms 57880 KB Output is correct
32 Correct 1249 ms 105108 KB Output is correct