#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define ins insert
#define pb push_back
#define F first
#define S second
const int N = 2e5+100, M = 5e5 + 7;
const int mod = 1e9 + 7;
int a[501][501], dp[501][501][502];
int dr[4] = {1, -1, 0, 0};
int dc[4] = {0, 0, 1, -1};
char dd[4] = {'S', 'N', 'E', 'W'};
char b[5001];
void solve(){
int n, m, k;
cin>>n>>m>>k;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
char c;
cin>>c;
if(c == '#') a[i][j] = 1;
else dp[i][j][1] = 1;
}
}
for(int i = 1; i <= k; i++){
cin>>b[i];
}
for(int l = 1; l <= k; l++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(!dp[i][j][l]) continue;
if(b[l] == '?'){
for(int o = 0; o < 4; o++){
int x = dr[o] + i, y = dc[o] + j;
if(x >= 1 && x <= n && y >= 1 && y <= m && !a[x][y]){
dp[x][y][l + 1] = 1;
}
}
}
else{
for(int o = 0; o < 4; o++){
if(b[l] != dd[o]) continue;
int x = dr[o] + i, y = dc[o] + j;
if(x >= 1 && x <= n && y >= 1 && y <= m && !a[x][y]){
dp[x][y][l + 1] = 1;
}
}
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(dp[i][j][k + 1]) ans++;
}
}
cout<<ans;
}
main(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin>>t;
for(int i = 1; i <= t; i++){
//cout<<"Case "<<i<<": ";
solve();
}
}
Compilation message (stderr)
nautilus.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |