제출 #723034

#제출 시각아이디문제언어결과실행 시간메모리
723034adrilenNautilus (BOI19_nautilus)C++17
66 / 100
1051 ms13432 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
constexpr int maxm = 5e3 + 1, maxa = 5e2 + 2;

bitset <maxa> ma[maxm][maxa];

vector<pii> dir[] = { vector<pii>{pii( -1, 0 )}, vector<pii>{pii( 1, 0 )}, vector<pii>{pii( 0, -1 )},
                    vector<pii>{pii( 0, 1 )}, vector<pii>{pii( -1, 0 ), pii(1, 0), pii(0, -1), pii(0, 1)}};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int r, c, m;
    cin >> r >> c >> m;

    string s;
    for (int y = 1; y <= r; y++)
    {
        cin >> s;
        for (int x = 1; x <= c; x++)
        {
            if (s[x - 1] == '.') ma[0][x][y] = true;
        }
    }
    int output;

    cin >> s;
    int typ;
    for (int i = 1; i <= m; i++)
    {
        if (s[i - 1]=='W') typ = 0;
        else if (s[i - 1]=='E') typ = 1;
        else if (s[i - 1]=='N') typ = 2; 
        else if (s[i - 1] == 'S') typ = 3;
        else typ = 4;

        // cout << dir[typ][0].first << " " << dir[typ][0].second << " " << dir[typ].size() <<"\n";

        for (int y = 1; y <= r; y++)
        {
            for (int x = 1; x <= c; x++)
            {
                for (pii &p : dir[typ])
                {
                    if (ma[0][x + p.first][y + p.second] && ma[i - 1][x][y]) 
                        ma[i][x + p.first][y + p.second] = true;
                }
            }
        }
    }
    // for (int i = 0; i <= m; i++)
    // {
    //     cout << i <<"\n";
    //     for (int y = 1; y <= r; y ++) 
    //     {
    //         for (int x = 1; x <= c; x++) cout << ma[i][x][y];
    //         cout << "\n";
    //     }
    //     cout <<"\n";
    // }

    output = 0;
    for (int x = 1; x <= c; x++)
    {
        output += ma[m][x].count();
    }
    cout << output << "\n";

    // cerr << clock() / static_cast<double>(CLOCKS_PER_SEC) << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...