Submission #138349

# Submission time Handle Problem Language Result Execution time Memory
138349 2019-07-29T19:40:29 Z silxikys Tracks in the Snow (BOI13_tracks) C++14
95.625 / 100
2000 ms 153756 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 4005;
int H, W;
char grid[maxn][maxn];
bool seen[maxn][maxn];

int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

bool valid(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grid[i][j];
        }
    }
    if (H == 1 && W == 1) {
        cout << 1 << '\n';
        return 0;
    }
    queue<pair<int,int>> q, nxt;
    nxt.push({0,0});
    seen[0][0] = true;
    char curr = grid[0][0];
    int ans = 0;
    while (true) {
        int added = 0;
        //cout << "level " << ans << '\n';
        while (!nxt.empty()) {
            q.push(nxt.front());
            nxt.pop();
        }
        while (!q.empty()) {
            auto p = q.front(); q.pop();
            //cout << p.first << ' ' << p.second << '\n';
            for (int k = 0; k < 4; k++) {
                int nx = p.first + dx[k];
                int ny = p.second + dy[k];
                if (!valid(nx,ny)) continue;
                if (seen[nx][ny]) continue;
                if (grid[nx][ny] != curr) continue;
                seen[nx][ny] = true;
                q.push({nx,ny});
                nxt.push({nx,ny});
                added++;
            }
        }
        /*
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << seen[i][j];
            }
            cout << '\n';
        }
        */
        curr = curr == 'R' ? 'F' : 'R';
        if (added == 0) break;
        ans++;
    }
    cout << ans << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 29 ms 4472 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 18 ms 4984 KB Output is correct
5 Correct 8 ms 2680 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 4 ms 1144 KB Output is correct
10 Correct 7 ms 2296 KB Output is correct
11 Correct 7 ms 2168 KB Output is correct
12 Correct 13 ms 2808 KB Output is correct
13 Correct 8 ms 2808 KB Output is correct
14 Correct 8 ms 2680 KB Output is correct
15 Correct 27 ms 4600 KB Output is correct
16 Correct 29 ms 4600 KB Output is correct
17 Correct 22 ms 4344 KB Output is correct
18 Correct 18 ms 4976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 30328 KB Output is correct
2 Correct 106 ms 11764 KB Output is correct
3 Correct 563 ms 47468 KB Output is correct
4 Correct 154 ms 18892 KB Output is correct
5 Correct 361 ms 32800 KB Output is correct
6 Correct 1970 ms 109872 KB Output is correct
7 Correct 34 ms 31736 KB Output is correct
8 Correct 32 ms 30328 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 32 ms 31224 KB Output is correct
12 Correct 4 ms 1528 KB Output is correct
13 Correct 112 ms 11664 KB Output is correct
14 Correct 62 ms 8440 KB Output is correct
15 Correct 50 ms 9208 KB Output is correct
16 Correct 50 ms 4088 KB Output is correct
17 Correct 295 ms 20216 KB Output is correct
18 Correct 168 ms 20088 KB Output is correct
19 Correct 155 ms 18924 KB Output is correct
20 Correct 138 ms 17528 KB Output is correct
21 Incorrect 166 ms 33784 KB Output isn't correct
22 Correct 362 ms 32888 KB Output is correct
23 Correct 555 ms 27768 KB Output is correct
24 Correct 351 ms 33832 KB Output is correct
25 Correct 667 ms 47480 KB Output is correct
26 Correct 1151 ms 142712 KB Output is correct
27 Correct 1527 ms 138296 KB Output is correct
28 Correct 1946 ms 109944 KB Output is correct
29 Execution timed out 2069 ms 99848 KB Time limit exceeded
30 Correct 1787 ms 127460 KB Output is correct
31 Correct 1370 ms 36512 KB Output is correct
32 Correct 1370 ms 153756 KB Output is correct