#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int, int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define endl '\n'
#define ld long double
#define sz(x) static_cast<int>((x).size())
const int sz=502;
signed main(){
int h,w,m;cin>>h>>w>>m;
vector<bitset<sz>> mat(h+2);
vector<vector<bitset<sz>>> pos(m+1, vector<bitset<sz>>(h+2));
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
char c;cin>>c;
if(c=='.'){
mat[i].set(j);
pos[0][i].set(j);
}
}
}
//~ cout<<endl;
//~ for(int j=1;j<=h;j++){
//~ cout<<pos[0][j]<<'\n';
//~ }cout<<endl;
string mvs;cin>>mvs;
for(int i=1;i<=m;i++){
for(int j=1;j<=h;j++){
if(mvs[i-1]=='N'){
pos[i][j]=pos[i-1][j+1] & mat[j];
}
else if(mvs[i-1]=='S'){
pos[i][j]=pos[i-1][j-1] & mat[j];
}
else if(mvs[i-1]=='E'){
pos[i][j]=(pos[i-1][j]<<1) & mat[j];
}
else if(mvs[i-1]=='W'){
pos[i][j]=(pos[i-1][j]>>1) & mat[j];
}
else {
pos[i][j]=(pos[i-1][j]<<1 | pos[i-1][j]>>1 | pos[i-1][j-1] | pos[i-1][j+1]) & mat[j];
}
//~ cout<<pos[i][j]<<'\n';
}
//~ cout<<endl;
}
int ans=0;
for(int i=1;i<=h;i++){
ans+=pos[m][i].count();
}
cout<<ans;
}
/*
1 3 2
...
E?
*/
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |