#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |