Submission #515641

# Submission time Handle Problem Language Result Execution time Memory
515641 2022-01-19T11:35:58 Z nhphucqt Nautilus (BOI19_nautilus) C++17
100 / 100
181 ms 396 KB
#include <bits/stdc++.h>

using namespace std;

const int D[4][2] = {{0,-1},{0,1},{-1,0},{1,0}};
const int NROW = 507;
const int NCOL = 507;
const int N = 5007;
int numRow, numCol, n;
bitset<NCOL> ans[NROW], tmp[NROW], islands[NROW];
int res;

void process(char c) {
    if (c == 'W') {
        for (int i = 1; i <= numRow; ++i) {
            ans[i] >>= 1;
            ans[i] &= islands[i];
        }
    }
    else if (c == 'E') {
        for (int i = 1; i <= numRow; ++i) {
            ans[i] <<= 1;
            ans[i] &= islands[i];
        }
    }
    else if (c == 'N') {
        for (int i = 1; i <= numRow; ++i) {
            ans[i] = ans[i+1] & islands[i];
        }
    }
    else if (c == 'S') {
        for (int i = numRow; i >= 1; --i) {
            ans[i] = ans[i-1] & islands[i];
        }
    }
    else {
        for (int i = 1; i <= numRow; ++i) {
            tmp[i] = ((ans[i]>>1) | (ans[i]<<1) | ans[i-1] | ans[i+1]) & islands[i];
        }
        for (int i = 1; i <= numRow; ++i) {
            ans[i] = tmp[i];
        }
    }

    // for (int i = 1; i <= numRow; ++i, cerr << '\n')
    // for (int j = 1; j <= numCol; ++j) cerr << ans[i][j];
    // cerr << '\n';
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    // freopen("NAUTILUS.inp", "r", stdin);
    // freopen("NAUTILUS.out", "w", stdout);

    cin >> numRow >> numCol >> n;
    for (int i = 1; i <= numRow; ++i)
    for (int j = 1; j <= numCol; ++j) {
        char c; cin >> c;
        islands[i][j] = c == '.';
        ans[i][j] = c == '.';
    }
    // for (int i = 1; i <= numRow; ++i, cerr << '\n')
    // for (int j = 1; j <= numCol; ++j) cerr << ans[i][j];
    // cerr << '\n';
    for (int i = 1; i <= n; ++i) {
        char c; cin >> c;
        process(c);
    }
    for (int i = 1; i <= numRow; ++i)
    for (int j = 1; j <= numCol; ++j) {
        res += ans[i][j];
    }
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 77 ms 388 KB Output is correct
23 Correct 79 ms 384 KB Output is correct
24 Correct 78 ms 392 KB Output is correct
25 Correct 79 ms 384 KB Output is correct
26 Correct 73 ms 332 KB Output is correct
27 Correct 135 ms 384 KB Output is correct
28 Correct 138 ms 384 KB Output is correct
29 Correct 136 ms 384 KB Output is correct
30 Correct 135 ms 384 KB Output is correct
31 Correct 132 ms 396 KB Output is correct
32 Correct 179 ms 388 KB Output is correct
33 Correct 178 ms 392 KB Output is correct
34 Correct 180 ms 388 KB Output is correct
35 Correct 181 ms 388 KB Output is correct
36 Correct 178 ms 332 KB Output is correct