Submission #1338944

#TimeUsernameProblemLanguageResultExecution timeMemory
1338944hoangtien69Nautilus (BOI19_nautilus)C++20
0 / 100
1 ms344 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;
            }
        }
    }
    for (int i = 0; i < R; i++)
    {
        for (int j = 0; j < C; j++)
        {
            peal[i][j] = a[i][j];
        }
    }
    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 = 1; i < R; 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++)
    {
        for (int j = 0; j < C; j++)
        {
            if (peal[i][j])
            {
                ans++;
            }
        }
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...