Submission #1263524

#TimeUsernameProblemLanguageResultExecution timeMemory
1263524Bui_Quoc_CuongNautilus (BOI19_nautilus)C++20
100 / 100
97 ms552 KiB
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define bitsex bitset

const int MAX = 5e2 + 5;

bitsex<MAX> f[2][MAX];
bitsex<MAX> a[MAX];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    string s;
    for (int i = 1; i <= n; i++) {
        cin >> s;
        for (int j = 0; j < m; j++) {
            if (s[m - j - 1] == '.') {
                a[i][j] = true;
            }
        }
        f[0][i] = a[i];
    }

    cin >> s;
    s = '#' + s;
    for (int j = 1; j <= k; j++) {
        for (int i = 1; i <= n; i++) {
            f[j & 1][i].reset();
            if (s[j] == 'W' || s[j] == '?') f[j & 1][i] |= f[(j - 1) & 1][i] << 1;
            if (s[j] == 'E' || s[j] == '?') f[j & 1][i] |= f[(j - 1) & 1][i] >> 1;
            if (i > 1 && (s[j] == 'S' || s[j] == '?')) f[j & 1][i] |= f[(j - 1) & 1][i - 1];
            if (i < n && (s[j] == 'N' || s[j] == '?')) f[j & 1][i] |= f[(j - 1) & 1][i + 1];
            f[j & 1][i] &= a[i];
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += f[k & 1][i].count();
    }

    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...