제출 #200566

#제출 시각아이디문제언어결과실행 시간메모리
200566johuthaNautilus (BOI19_nautilus)C++14
66 / 100
1089 ms760 KiB
#include <iostream>
#include <vector>
#include <algorithm>

#define int int64_t

using namespace std;

signed main()
{
    int r, c, m;
    cin >> r >> c >> m;

    vector<vector<bool>> tab;
    vector<vector<bool>> st(r, vector<bool>(c));
    vector<vector<bool>> old(r, vector<bool>(c));

    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            char ch;
            cin >> ch;
            st[i][j] = (ch == '.');
        }
    }

    tab = st;

    string seq;
    cin >> seq;
    // reverse(seq.begin(), seq.end());
    for (int i = 0; i < m; i++)
    {
        if (seq[i] == 'N') seq[i] = 'S';
        else if (seq[i] == 'S') seq[i] = 'N';
        else if (seq[i] == 'E') seq[i] = 'W';
        else if (seq[i] == 'W') seq[i] = 'E';
    }

    for (int t = 0; t < m; t++)
    {
        swap(old, tab);
        for (int i = 0; i < r; i++)
        {
            for (int j = 0; j < c; j++)
            {
                tab[i][j] = false;
                if (seq[t] == 'N' || seq[t] == '?') tab[i][j] = tab[i][j] || ((i - 1 >= 0) ? old[i - 1][j] : false);
                if (seq[t] == 'W' || seq[t] == '?') tab[i][j] = tab[i][j] || ((j - 1 >= 0) ? old[i][j - 1] : false);
                if (seq[t] == 'S' || seq[t] == '?') tab[i][j] = tab[i][j] || ((i + 1 < r) ? old[i + 1][j] : false);
                if (seq[t] == 'E' || seq[t] == '?') tab[i][j] = tab[i][j] || ((j + 1 < c) ? old[i][j + 1] : false);
                tab[i][j] = tab[i][j] && st[i][j];
            }
        }
        /*
        for (auto v : tab)
        {
            for (auto j : v)
            {
                cout << j << " ";
            }
            cout << "\n";
        }
        cout << "\n";
        */
    }

    int res = 0;
    for (auto v : tab) for (auto j : v) res += j;
    cout << res << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...