Submission #159015

# Submission time Handle Problem Language Result Execution time Memory
159015 2019-10-20T05:59:41 Z FutymyClone Tracks in the Snow (BOI13_tracks) C++14
91.25 / 100
1219 ms 1048580 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 4005;

int n, m, ans = 0;
bool visited[N][N];
string a[N];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};

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

void bfs (queue <pair <int, int> > q1, queue <pair <int, int> > q2) {
    if (q1.empty()) return;
    ans++;
    while (!q1.empty()) {
        int x = q1.front().first, y = q1.front().second; q1.pop();
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (!ok(nx, ny)) continue;
            visited[nx][ny] = true;
            if (a[nx][ny] == a[x][y]) q1.push({nx, ny});
            else q2.push({nx, ny});
        }
    }

    bfs(q2, q1);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    queue <pair <int, int> > q1, q2;
    q1.push({0, 0});
    visited[0][0] = true;
    bfs(q1, q2);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3704 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 11 ms 2808 KB Output is correct
5 Correct 5 ms 1912 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 5 ms 1784 KB Output is correct
11 Correct 5 ms 1412 KB Output is correct
12 Correct 9 ms 2040 KB Output is correct
13 Correct 5 ms 1912 KB Output is correct
14 Correct 5 ms 1912 KB Output is correct
15 Correct 18 ms 3576 KB Output is correct
16 Correct 20 ms 3704 KB Output is correct
17 Correct 16 ms 3192 KB Output is correct
18 Correct 12 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 22776 KB Output is correct
2 Correct 66 ms 10816 KB Output is correct
3 Correct 1219 ms 883680 KB Output is correct
4 Correct 77 ms 14968 KB Output is correct
5 Runtime error 919 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Correct 1096 ms 59244 KB Output is correct
7 Correct 28 ms 22520 KB Output is correct
8 Correct 28 ms 22776 KB Output is correct
9 Correct 4 ms 1016 KB Output is correct
10 Correct 6 ms 4216 KB Output is correct
11 Correct 24 ms 18808 KB Output is correct
12 Correct 18 ms 16888 KB Output is correct
13 Correct 66 ms 10680 KB Output is correct
14 Correct 38 ms 7416 KB Output is correct
15 Correct 258 ms 210560 KB Output is correct
16 Correct 35 ms 5240 KB Output is correct
17 Correct 176 ms 24460 KB Output is correct
18 Correct 1136 ms 806048 KB Output is correct
19 Correct 78 ms 15096 KB Output is correct
20 Correct 282 ms 184412 KB Output is correct
21 Correct 751 ms 498724 KB Output is correct
22 Runtime error 986 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Correct 349 ms 39392 KB Output is correct
24 Runtime error 956 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 1044 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Correct 595 ms 27744 KB Output is correct
27 Correct 799 ms 37036 KB Output is correct
28 Correct 1035 ms 59208 KB Output is correct
29 Correct 1012 ms 58388 KB Output is correct
30 Correct 882 ms 53260 KB Output is correct
31 Correct 889 ms 68252 KB Output is correct
32 Correct 697 ms 35944 KB Output is correct