Submission #1325896

#TimeUsernameProblemLanguageResultExecution timeMemory
1325896sh_qaxxorov_571Nautilus (BOI19_nautilus)C++20
100 / 100
108 ms544 KiB
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
using namespace std;
const int MAXC = 505;
bitset<MAXC> can_be[505], next_can_be[505], land[505];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int R, C, M;
    cin >> R >> C >> M;

    for (int i = 0; i < R; ++i) {
        string row;
        cin >> row;
        for (int j = 0; j < C; ++j) {
            if (row[j] == '.') {
                can_be[i][j] = 1;
                land[i][j] = 1;  
            } else {
                land[i][j] = 0;  
            }
        }
    }

    string signals;
    cin >> signals;

    for (char s : signals) {
        for (int i = 0; i < R; ++i) next_can_be[i].reset();

        if (s == 'N' || s == '?') {
            for (int i = 0; i < R - 1; ++i)
                next_can_be[i] |= (can_be[i + 1]);
        }
        if (s == 'S' || s == '?') {
            for (int i = 1; i < R; ++i)
                next_can_be[i] |= (can_be[i - 1]);
        }
        if (s == 'E' || s == '?') {
            for (int i = 0; i < R; ++i)
                next_can_be[i] |= (can_be[i] << 1);
        }
        if (s == 'W' || s == '?') {
            for (int i = 0; i < R; ++i)
                next_can_be[i] |= (can_be[i] >> 1);
        }
        for (int i = 0; i < R; ++i) {
            can_be[i] = next_can_be[i] & land[i];
        }
    }

    int result = 0;
    for (int i = 0; i < R; ++i) {
        for(int j = 0; j < C; j++) {
            if(can_be[i][j]) result++;
        }
    }

    cout << result << endl;

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