제출 #140686

#제출 시각아이디문제언어결과실행 시간메모리
140686MinnakhmetovNautilus (BOI19_nautilus)C++14
100 / 100
213 ms1064 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...