Submission #570219

#TimeUsernameProblemLanguageResultExecution timeMemory
570219danikoynovNautilus (BOI19_nautilus)C++14
100 / 100
253 ms724 KiB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 510;
int n, m, l;
bitset < maxn > bt[maxn], base[maxn], cur[maxn], pos[maxn];

void go_north()
{
    for (int i = 0; i <= n + 1; i ++)
        pos[i] = bt[i + 1];
    for (int i = 0; i <= n + 1; i ++)
        cur[i] = (cur[i] | pos[i]);
}

void go_south()
{
    for (int i = 1; i <= n + 1; i ++)
        pos[i] = bt[i - 1];
    for (int i = 0; i <= n + 1; i ++)
        cur[i] = (cur[i] | pos[i]);
}

void go_east()
{
    for (int i = 0; i <= n + 1; i ++)
        pos[i] = (bt[i] << 1);
            for (int i = 0; i <= n + 1; i ++)
        cur[i] = (cur[i] | pos[i]);
}

void go_west()
{
    for (int i = 0; i <= n + 1; i ++)
        pos[i] = (bt[i] >> 1);
            for (int i = 0; i <= n + 1; i ++)
        cur[i] = (cur[i] | pos[i]);
}
void solve()
{
    cin >> n >> m >> l;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
    {
        char c;
        cin >> c;
        if (c == '.')
            bt[i][j] = 1, base[i][j] = 1;
    }

    for (int t = 1; t <= l; t ++)
    {
        for (int i = 0; i <= n + 1; i ++)
            cur[i].reset();
        char c;
        cin >> c;
        if (c == 'N' || c =='?')
        go_north();
        if (c == 'E' || c == '?')
            go_east();
        if (c == 'S' || c == '?')
        go_south();
        if (c == 'W' || c == '?')
            go_west();

            /**for (int i = 1; i <= n; i ++, cout << endl)
                for (int j = 1; j <= m; j ++)
                cout << bt[i][j];
        cout << "---------------" << endl;*/
        for (int i = 0; i <= n + 1; i ++)
        bt[i] = cur[i], bt[i] = (bt[i] & base[i]);

    }

    int ans = 0;
    for (int i = 1; i <= n; i ++)
    for (int j = 1; j <= m; j ++)
    ans += bt[i][j];

    cout << ans << endl;




}

int main()
{
    solve();
    return 0;
}

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