Submission #101518

# Submission time Handle Problem Language Result Execution time Memory
101518 2019-03-19T03:33:10 Z lyc Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1338 ms 44080 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w; cin >> h >> w;
    string g[h];
    for (int i = 0; i < h; ++i) {
        cin >> g[i];
    }

    int dy[] = {-1, 0, 1, 0};
    int dx[] = {0, 1, 0, -1};
    bool vis[h][w]; memset(vis, 0, sizeof vis);
    int ans = 0;
    queue<ii> q[2];
    q[0].push(ii(0, 0));
    vis[0][0] = 1;
    while ((!q[0].empty()) || (!q[1].empty())) {
        for (int x = 0; x < 2; ++x) {
            if (!q[x].empty()) ++ans;
            while (!q[x].empty()) {
                ii u = q[x].front(); q[x].pop();
                for (int i = 0; i < 4; ++i) {
                    ii v = ii(u.fi + dy[i], u.sc + dx[i]);
                    if (v.fi >= 0 && v.fi < h && v.sc >= 0 && v.sc < w && g[v.fi][v.sc] != '.' && !vis[v.fi][v.sc]) {
                        if (g[v.fi][v.sc] == g[u.fi][u.sc]) {
                            q[x].push(v);
                        }
                        else {
                            q[!x].push(v);
                        }
                        vis[v.fi][v.sc] = 1;
                    }
                }
            }
        }
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 896 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 11 ms 896 KB Output is correct
16 Correct 15 ms 976 KB Output is correct
17 Correct 10 ms 896 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 48 ms 3584 KB Output is correct
3 Correct 207 ms 33912 KB Output is correct
4 Correct 71 ms 8064 KB Output is correct
5 Correct 132 ms 18944 KB Output is correct
6 Correct 1189 ms 44016 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 53 ms 3584 KB Output is correct
14 Correct 28 ms 2176 KB Output is correct
15 Correct 19 ms 2432 KB Output is correct
16 Correct 23 ms 1664 KB Output is correct
17 Correct 128 ms 8576 KB Output is correct
18 Correct 64 ms 8576 KB Output is correct
19 Correct 66 ms 8064 KB Output is correct
20 Correct 54 ms 7424 KB Output is correct
21 Correct 136 ms 19604 KB Output is correct
22 Correct 194 ms 18936 KB Output is correct
23 Correct 320 ms 16416 KB Output is correct
24 Correct 142 ms 19192 KB Output is correct
25 Correct 369 ms 33884 KB Output is correct
26 Correct 633 ms 25976 KB Output is correct
27 Correct 899 ms 35440 KB Output is correct
28 Correct 1338 ms 44080 KB Output is correct
29 Correct 1214 ms 42640 KB Output is correct
30 Correct 924 ms 40968 KB Output is correct
31 Correct 810 ms 22104 KB Output is correct
32 Correct 695 ms 34680 KB Output is correct