Submission #1157021

#TimeUsernameProblemLanguageResultExecution timeMemory
1157021htphong0909Nautilus (BOI19_nautilus)C++20
100 / 100
173 ms160208 KiB
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

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

bitset<501> DP[5011][510];
bitset<501> arr[510];


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, h;
    cin >> n >> m >> h;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            char x;
            cin >> x;
            if (x == '.') arr[i][j] = true;
        }
        DP[0][i] = arr[i];
    }
    string s;
    cin >> s;
    s = '.' + s;
    int ans = 0;
    for (int k = 1; k <= h; k++) {
        for (int i = 1; i <= n; i++) {
            if (s[k] == 'N' || s[k] == '?') DP[k][i] |= DP[k - 1][i + 1];
            if (s[k] == 'S' || s[k] == '?') DP[k][i] |= DP[k - 1][i - 1] ;
            if (s[k] == 'W' || s[k] == '?') DP[k][i] |= DP[k - 1][i] >> 1LL;
            if (s[k] == 'E' || s[k] == '?') DP[k][i] |= DP[k - 1][i] << 1LL;
            DP[k][i] &= arr[i];
            if (k == h) ans += DP[k][i].count();
        }
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...