#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())
signed main(){
	int h,w,m;cin>>h>>w>>m;
	vector<vector<bool>> mat(h, vector<bool>(m, 0));
	vector<pair<int,int>> pos;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char c;cin>>c;
			if(c=='.'){
				pos.pb({i,j});
				mat[i][j]=1;
			}
		}
	}
	
	int dir[4][2]={{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
	string mvs;cin>>mvs;
	
	for(int i=0;i<m;i++){
		vector<pair<int,int>> nw;
		vector<vector<int>> vis(h, vector<int>(w,0));
		int ind=0,nx, ny;
		if(mvs[i]=='?'){
			for(ind=0;ind<=3;ind++){
				for(auto [x, y]:pos){
					nx=x+dir[ind][0], ny=y+dir[ind][1];
					if(nx<0 or nx>=h or ny<0 or ny>=w or !mat[nx][ny])continue;
					if (vis[nx][ny])continue;
					nw.pb({nx,ny});
					vis[nx][ny]=true;
				}
			}
			swap(nw,pos);
			continue;
		}
		if(mvs[i]=='N') ind=1;
		else if(mvs[i]=='E')ind=2;
		else if(mvs[i]=='S')ind=0;
		else if(mvs[i]=='W')ind=3;
		for(auto [x, y]:pos){
			nx=x+dir[ind][0], ny=y+dir[ind][1];
			if(nx<0 or nx>=h or ny<0 or ny>=w or !mat[nx][ny] or vis[nx][ny])continue;
			nw.pb({nx,ny});
			vis[nx][ny]=true;
		}
		swap(nw,pos);
		
	}	
	cout<<pos.size();
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |