Submission #1338946

#TimeUsernameProblemLanguageResultExecution timeMemory
1338946hoangtien69Nautilus (BOI19_nautilus)C++20
100 / 100
98 ms552 KiB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 505;

int R, M, C;
bitset<MAXN> a[MAXN];
bitset<MAXN> peal[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> R >> C >> M;
    for (int i = 0; i < R; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < C; j++)
        {
            if (s[j] == '.')
            {
                a[i][j] = 1;
                peal[i][j] = 1;
            }
        }
    }
    string query;
    cin >> query;
    for (char x : query)
    {
        if (x == 'W')
        {
            for (int i = 0; i < R; i++)
            {
                peal[i] = (peal[i] >> 1);
            }
        }
        else if (x == 'E')
        {
            for (int i = 0; i < R; i++)
            {
                peal[i] = (peal[i] << 1);
            }
        }
        else if (x == 'S')
        {
            for (int i = R-1; i > 0; i--)
            {
                peal[i] = peal[i-1];
            }
            peal[0] = 0;
        }
        else if (x == 'N')
        {
            for (int i = 0; i < R-1; i++)
            {
                peal[i] = peal[i+1];
            }
            peal[R-1] = 0;
        }
        else if (x == '?')
        {
            bitset<MAXN> cur[MAXN];
            for (int i = 0; i < R; i++)
            {
                if (i > 0) cur[i] |= peal[i-1];
                if (i < R-1) cur[i] |= peal[i+1];
                cur[i] |= (peal[i] << 1);
                cur[i] |= (peal[i] >> 1);
            }
            for (int i = 0; i < R; i++)
            {
                peal[i] = cur[i];
            }
        }
        for (int i = 0; i < R; i++)
        {
            peal[i] &= a[i];
        }
    }
    int ans = 0;
    for (int i = 0; i < R; i++)
    {
        ans += peal[i].count();
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...