Submission #393453

#TimeUsernameProblemLanguageResultExecution timeMemory
393453inventiontimeNautilus (BOI19_nautilus)C++17
100 / 100
216 ms708 KiB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;

int R, C, M;
bitset<502> W[502] = {};
bitset<502> pos[2][502] = {};
queue<ii> pts;
string I;

int main() {
    cin >> R >> C >> M;

    char c;
    for(int i = 1; i <= R; i++) for(int j = 1; j <= C; j++) {
        cin >> c;
        W[i][j] = c == '.';
        pos[1][i][j] = W[i][j];
    }

    cin >> I;
    for(int k = 0; k < M; k++)
        for(int i = 1; i <= R; i++) {
            switch(I[k]) {
                case 'N':
                pos[k % 2][i] = pos[(k % 2) ^ 1][i+1] & W[i];
                break;

                case 'S':
                pos[k % 2][i] = pos[(k % 2) ^ 1][i-1] & W[i];
                break;

                case 'E':
                pos[k % 2][i] = pos[(k % 2) ^ 1][i] << 1 & W[i];
                break;

                case 'W':
                pos[k % 2][i] = pos[(k % 2) ^ 1][i] >> 1 & W[i];
                break;

                case '?':
                pos[k % 2][i] = (
                      (pos[(k % 2) ^ 1][i] << 1)
                    | (pos[(k % 2) ^ 1][i] >> 1)
                    | pos[(k % 2) ^ 1][i-1]
                    | pos[(k % 2) ^ 1][i+1]) & W[i];
                break;
            }
        }

    int res = 0;
    for(int i = 1; i <= R; i++) for(int j = 1; j <= C; j++) {
        if(pos[(M % 2) ^ 1][i][j])
            res++;
    }

    cout << res << endl;

    return 0;
}

/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...