Submission #414717

# Submission time Handle Problem Language Result Execution time Memory
414717 2021-05-31T05:44:35 Z tengiz05 Nautilus (BOI19_nautilus) C++17
100 / 100
368 ms 157548 KB
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 501, K = 5001;
char g[N][N];
std::bitset<N> dp[K][N];
std::bitset<N> a[N];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, m, k;
    std::cin >> n >> m >> k;
    memset(g, '#', sizeof g);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            std::cin >> g[i][j];
            a[i][j] = (g[i][j] == '.');
        }
    }
    std::string s;
    std::cin >> s;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[0][i][j] = (g[i][j] == '.');
        }
    }
    for (int K = 1; K <= k; K++) {
        for (int i = 1; i <= n; i++) {
            int x = 0, y = 0;
            if (s[K - 1] == 'N') x++;
            else if (s[K - 1] == 'S') x--;
            else if (s[K - 1] == 'W') y++;
            else if (s[K - 1] == 'E') y--;
            else {
                dp[K][i] = dp[K][i] | dp[K - 1][i - 1];
                dp[K][i] = dp[K][i] | (dp[K - 1][i] << 1);
                dp[K][i] = dp[K][i] | dp[K - 1][i + 1];
                dp[K][i] = dp[K][i] | (dp[K - 1][i] >> 1);
                dp[K][i] &= a[i];
                continue;
            }
            if (x) dp[K][i] = a[i] & dp[K - 1][i + x];
            else if (y == -1) {
                dp[K][i] = a[i] & (dp[K - 1][i] << 1);
            } else if (y == 1) {
                dp[K][i] = a[i] & (dp[K - 1][i] >> 1);
            } else assert(false);
        }
        // for (int i = 1; i <= n; i++) {
        //     for (int j = 1; j <= m; j++) {
        //         std::cout << dp[K][i][j];
        //     }
        //     std::cout << "\n";
        // }
        // std::cout << "\n";
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            ans += dp[k][i][j];
        }
    }
    std::cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 3 ms 1484 KB Output is correct
9 Correct 2 ms 1484 KB Output is correct
10 Correct 2 ms 1484 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 3 ms 1484 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 3 ms 1484 KB Output is correct
15 Correct 3 ms 1604 KB Output is correct
16 Correct 2 ms 1484 KB Output is correct
17 Correct 3 ms 1484 KB Output is correct
18 Correct 3 ms 1484 KB Output is correct
19 Correct 3 ms 1484 KB Output is correct
20 Correct 3 ms 1484 KB Output is correct
21 Correct 3 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 3 ms 1484 KB Output is correct
9 Correct 2 ms 1484 KB Output is correct
10 Correct 2 ms 1484 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 3 ms 1484 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 3 ms 1484 KB Output is correct
15 Correct 3 ms 1604 KB Output is correct
16 Correct 2 ms 1484 KB Output is correct
17 Correct 3 ms 1484 KB Output is correct
18 Correct 3 ms 1484 KB Output is correct
19 Correct 3 ms 1484 KB Output is correct
20 Correct 3 ms 1484 KB Output is correct
21 Correct 3 ms 1484 KB Output is correct
22 Correct 217 ms 157464 KB Output is correct
23 Correct 213 ms 157536 KB Output is correct
24 Correct 198 ms 157484 KB Output is correct
25 Correct 195 ms 157468 KB Output is correct
26 Correct 194 ms 157508 KB Output is correct
27 Correct 284 ms 157448 KB Output is correct
28 Correct 321 ms 157416 KB Output is correct
29 Correct 283 ms 157548 KB Output is correct
30 Correct 288 ms 157364 KB Output is correct
31 Correct 278 ms 157432 KB Output is correct
32 Correct 343 ms 157440 KB Output is correct
33 Correct 353 ms 157424 KB Output is correct
34 Correct 368 ms 157384 KB Output is correct
35 Correct 349 ms 157384 KB Output is correct
36 Correct 349 ms 157488 KB Output is correct