Submission #1324285

#TimeUsernameProblemLanguageResultExecution timeMemory
1324285edoNautilus (BOI19_nautilus)C++20
0 / 100
1 ms332 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    int R, C, M;
    cin >> R >> C >> M;
    vector<string> grid(R);
    for(int i = 0; i < R; i++) 
        cin >> grid[i];
    string s;
    cin >> s;

    bitset<501> ok[R], good[R], nxt[R];

    for(int i = 0; i < R; ++i) 
        for(int j = 0; j < C; ++j) 
            good[i][j] = ok[i][j] = grid[i][C - j - 1] == '.';

    for(char c : s) {
        for(int i = 0; i < R; ++i) 
            nxt[i].reset();
        if(c == 'W')
            for(int i = 0; i < R; ++i)
                nxt[i] = good[i] << 1;
        else if(c == 'E')
            for(int i = 0; i < R; ++i)
                nxt[i] = good[i] >> 1;
        else if(c == 'N')
            for(int i = 1; i < R; ++i)
                nxt[i - 1] = nxt[i];
        else if(c == 'S') 
            for(int i = 0; i < R - 1; ++i)
                nxt[i + 1] = good[i];
        else {
            for(int i = 0; i < R; ++i) {
                nxt[i] |= good[i] << 1;
                nxt[i] |= good[i] >> 1;
                if(i)  
                    nxt[i] |= good[i - 1];
                if(i + 1 < R)
                    nxt[i] |= good[i + 1];
            }
        }

        for(int i = 0; i < R; ++i) 
            nxt[i] &= ok[i];

        for(int i = 0; i < R; ++i) 
            good[i] = nxt[i];
    }

    int ans = 0;
    for(int i = 0; i < R; ++i) 
        ans += (int)good[i].count();

    cout << ans;
    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...