Submission #706857

#TimeUsernameProblemLanguageResultExecution timeMemory
706857stevancvNautilus (BOI19_nautilus)C++14
100 / 100
139 ms724 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 500 + 5;
const int inf = 2e9;
const int mod = 1e9 + 7;
bitset<N> a[N], dp[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (int j = 0; j < m; j++) {
            if (s[j] == '.') a[i][j] = dp[i][j] = 1;
            else a[i][j] = dp[i][j] = 0;
        }
    }
    string str; cin >> str;
    for (int z = 0; z < k; z++) {
        char ch = str[z];
        bitset<N> ndp[N];
        for (int i = 0; i < n; i++) {
            if (ch == 'N' && i < n - 1) ndp[i] = dp[i + 1];
            if (ch == 'S' && i > 0) ndp[i] = dp[i - 1];
            if (ch == 'W') ndp[i] = (dp[i] >> 1);
            if (ch == 'E') ndp[i] = (dp[i] << 1);
            if (ch == '?') {
                if (i < n - 1) ndp[i] |= dp[i + 1];
                if (i > 0) ndp[i] |= dp[i - 1];
                ndp[i] |= (dp[i] << 1);
                ndp[i] |= (dp[i] >> 1);
            }
            ndp[i] &= a[i];
        }
        swap(dp, ndp);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) ans += dp[i].count();
    cout << ans << en;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...