제출 #680684

#제출 시각아이디문제언어결과실행 시간메모리
680684four_specksNautilus (BOI19_nautilus)C++17
0 / 100
2 ms724 KiB
#include <bits/stdc++.h>

using namespace std;

namespace
{
} // namespace

using BS = bitset<250'000>;

void solve()
{
    int r, c, m;
    cin >> r >> c >> m;

    vector<string> grid(r);
    for (string &row : grid)
        cin >> row;

    string s;
    cin >> s;

    auto idx = [&](int i, int j) -> int
    { return c * i + j; };

    BS base;
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            if (grid[i][j] == '.')
            {
                int k = idx(i, j);
                base[k] = 1;
            }
        }
    }

    BS lft = base, rgt = base;
    for (int i = 0; i < r; i++)
        lft[i * c] = 0;
    for (int i = 0; i < r; i++)
        rgt[i * c + c - 1] = 0;

    BS can = base;
    for (char x : s)
    {
        if (x == 'N')
            can = (can << r) & base;
        else if (x == 'E')
            can = ((can & lft) << 1) & base;
        else if (x == 'W')
            can = ((can & rgt) >> 1) & base;
        else if (x == 'S')
            can = (can >> r) & base;
        else
            can = ((can << r) | ((can & lft) << 1) | ((can & rgt) >> 1) | (can >> r)) & base;
    }

    cout << can.count() << '\n';
}

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

    solve();

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