Submission #140686

# Submission time Handle Problem Language Result Execution time Memory
140686 2019-08-04T14:05:21 Z Minnakhmetov Nautilus (BOI19_nautilus) C++14
100 / 100
213 ms 1064 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 505;
char s[N][N];
bitset<N> dp[2][N], water[N];

int r, c, m;

void horizontalShift(int i, int d) {
    for (int x = 0; x < r; x++) {
        if (d < 0) {
            dp[i ^ 1][x] |= dp[i][x] >> -d;
        }
        else {
            dp[i ^ 1][x] |= dp[i][x] << d;   
        }
    }
}

void verticalShift(int i, int d) {
    for (int x = 0; x < r; x++) {
        if (x + d >= 0 && x + d < r)
            dp[i ^ 1][x + d] |= dp[i][x];
    }
}

signed main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> r >> c >> m;

    for (int i = 0; i < r; i++) {
        cin >> s[i];
        for (int j = 0; j < c; j++) {
            if (s[i][j] == '.') {
                water[i][j] = 1;
                dp[0][i][j] = 1;
            }
        }
    }

    string s;
    cin >> s;

    for (int i = 0, j = 0; i < m; i++, j ^= 1) {
        for (int k = 0; k < r; k++) {
            dp[j ^ 1][k].reset();
        }

        if (s[i] == 'W') {
            horizontalShift(j, -1);
        }
        else if (s[i] == 'E') {
            horizontalShift(j, 1);
        }
        else if (s[i] == 'N') {
            verticalShift(j, -1);
        }
        else if (s[i] == 'S') {
            verticalShift(j, 1);
        }
        else {
            horizontalShift(j, 1);
            horizontalShift(j, -1);
            verticalShift(j, -1);
            verticalShift(j, 1);
        }

        for (int k = 0; k < r; k++) {
            dp[j ^ 1][k] &= water[k];
        }
    }

    int ans = 0;

    for (int i = 0; i < r; i++)
        ans += dp[m & 1][i].count();

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 3 ms 508 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 3 ms 508 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 114 ms 992 KB Output is correct
23 Correct 115 ms 1064 KB Output is correct
24 Correct 112 ms 1016 KB Output is correct
25 Correct 112 ms 888 KB Output is correct
26 Correct 111 ms 1016 KB Output is correct
27 Correct 169 ms 1016 KB Output is correct
28 Correct 171 ms 992 KB Output is correct
29 Correct 170 ms 1016 KB Output is correct
30 Correct 170 ms 996 KB Output is correct
31 Correct 167 ms 888 KB Output is correct
32 Correct 213 ms 996 KB Output is correct
33 Correct 213 ms 996 KB Output is correct
34 Correct 213 ms 888 KB Output is correct
35 Correct 213 ms 992 KB Output is correct
36 Correct 212 ms 972 KB Output is correct