Submission #1187923

#TimeUsernameProblemLanguageResultExecution timeMemory
1187923AzeTurk810Nautilus (BOI19_nautilus)C++20
66 / 100
1095 ms3140 KiB
// Telebe of adicto yani AzeTurk810
//
// WHY ARE YOU STARING MY CODE Stranger ??!!
//
//GO AWAY AND DON T look my CODE if i don t know you or you are stalker !!!!(hrrr)
//
// here about me: I am alone of course, fun , ' , ' , love pyhcics , young(child) , love music , had birds , not a gamer , chess :) , dead to football , you are looking to code , ... ;
//
// why at 1 japon army march they say "the enemy geniral is a hero , an equal to no one. Both in glory and in victory
// the men that follow him are also breave , fearless wariors ..."?
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

# define ln '\n'
# define ff first
# define ss second
# define INFll 1e18

vector<vector<char>> g;
vector<vector<char>> used;

int dx[] = {1 , -1 , 0 , 0};
int dy[] = {0 , 0 , 1 , -1};

void solve() {
    int r , c , m;
    string s;
    cin >>r >> c >> m;
    g.resize(r , vector<char>(c));
    used.assign(r , vector<char>(c , false));
    queue<pair<int,int>> q;
    char x;
    for(int i = 0 ; i < r ; i ++) {
        for(int j = 0 ; j < c ; j ++) {
            cin >> x;
            if(x == '.') {
                g[i][j] = true;
                q.push({i , j});
            } else {
                g[i][j] = false;
            }
        }
    }
    cin >> s;
    int full;
    queue<pair<int,int>> temp;
    for(char &cur : s) {
        if(cur == '?') {
            full = -1;
        } else {
            if(cur == 'N') full = 2;
            else if(cur == 'W') full = 4;
            else if(cur == 'E') full = 3;
            else full = 1;
            full--;
        }
        while(!q.empty()) {
            auto [x , y] = q.front();
            q.pop();
            if(full == -1 ) {
                for(int k = 0 ; k < 4 ; k ++) {
                    int curi = x + dx[k] , curj = y + dy[k];
                    if(curi < 0 || curj < 0 || curi >= r || curj >= c) continue;
                    if(!used[curi][curj] && g[curi][curj]) {
                        used[curi][curj] = true;
                        temp.push({curi , curj});
                    }
                }
            } else {
                int curi = x + dx[full] , curj = y + dy[full];
                if(curi < 0 || curj < 0 || curi >= r || curj >= c) continue;
                if(!used[curi][curj] && g[curi][curj]) {
                    used[curi][curj] = true;
                    temp.push({curi , curj});
                }
            }
        }
        while(!temp.empty()) {
            auto [x , y] = temp.front();
            temp.pop();
            used[x][y ] =false;
            q.push({x , y});
        }
    }
    cout << q.size() << ln;
} 


signed main() {
//    build();
    int t = 1;
    while(t--)solve();

}

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