#include <bits/stdc++.h>
using namespace std;
bitset<250000> l, r, u, d, f, dp;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, k; cin >> n >> m >> k;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
char c; cin >> c;
int x = i * m + j;
f[x] = (c == '.');
u[x] = (i > 0);
l[x] = (j > 0);
d[x] = (i + 1 < n);
r[x] = (j + 1 < m);
}
}
string s; cin >> s;
dp = f;
for(char x: s){
if(x == '?') dp = (((dp & u) >> m) | ((dp & r) << 1) | ((dp & d) << m) | ((dp & l) >> 1)) & f;
if(x == 'N') dp = ((dp & u) >> m) & f;
if(x == 'E') dp = ((dp & r) << 1) & f;
if(x == 'S') dp = ((dp & d) << m) & f;
if(x == 'W') dp = ((dp & l) >> 1) & f;
}
cout << dp.count();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |