제출 #1187948

#제출 시각아이디문제언어결과실행 시간메모리
1187948kamal1122333Nautilus (BOI19_nautilus)C++20
29 / 100
1097 ms328 KiB
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define f first
#define s second
using namespace std;

ll n, m, k;
string ord;
vector<vector<char>> v;
vector<vector<bool>> c, c2;
ll say=0;

void dfs(ll x, ll y, ll ind){
    if (x < 1 || x > n || y < 1 || y > m || v[x][y] == '#') return;
    if (ind==k and c2[x][y]==0){
        say++;
        c[x][y]=1;
        c2[x][y]=1;
        return;
    }
    else if (ind==k) return;
    c[x][y]=1;
    if (ord[ind]=='?'){
        dfs(x+1, y, ind+1);
        dfs(x-1, y, ind+1);
        dfs(x, y+1, ind+1);
        dfs(x, y-1, ind+1);
    }
    else if (ord[ind]=='N') dfs(x-1, y, ind+1);
    else if (ord[ind]=='S') dfs(x+1, y, ind+1);
    else if (ord[ind]=='E') dfs(x, y+1, ind+1);
    else if (ord[ind]=='W') dfs(x, y-1, ind+1);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    v.resize(n+1, vector<char>(m+1));
    c2.resize(n+1, vector<bool>(m+1));
    for (int i=1; i<=n; i++){
        for (int j=1; j<=m; j++){
            cin>>v[i][j];
        }
    }
    cin>>ord;
    for (int i=1; i<=n; i++){
        for (int j=1; j<=m; j++){
            c.assign(n+1, vector<bool>(m+1, 0));
            dfs(i, j, 0);
        }
    }
    cout<<say<<endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...