제출 #897982

#제출 시각아이디문제언어결과실행 시간메모리
897982LCJLYNautilus (BOI19_nautilus)C++14
100 / 100
548 ms2136 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;

//int n,m,k;
//string arr[105];
//vector<pii>dir[105];
//int memo[105][105][105];

//int dp(int index, int pos, int pos2){
	//if(index==k) return 1;
	//if(memo[index][pos][pos2]!=-1) return memo[index][pos][pos2];
	//int ans=0;
	
	//for(auto it:dir[index]){
		//int newx=pos+it.first;
		//int newy=pos2+it.second;
		//if(newx<0||newy<0||newx>=n||newy>=m) continue;
		//if(arr[newx][newy]=='#') continue;
		//ans|=dp(index+1,newx,newy);
	//}
	////show3(index,index,pos,pos,pos2,pos2);
	////show(ans,ans);
	//return memo[index][pos][pos2]=ans;
//}

void solve(){	
	//cin >> n >> m >> k;
	
	//for(int x=0;x<n;x++){
		//cin >> arr[x];
	//}
	
	
	//string s;
	//cin >> s;
	
	//reverse(s.begin(),s.end());
	//for(int x=0;x<k;x++){
		//if(s[x]=='N'){
			//dir[x].push_back({1,0});
		//}
		//else if(s[x]=='S'){
			//dir[x].push_back({-1,0});
		//}
		//else if(s[x]=='W'){
			//dir[x].push_back({0,1});
		//}
		//else if(s[x]=='E'){
			//dir[x].push_back({0,-1});
		//}
		//else{
			//dir[x].push_back({1,0});
			//dir[x].push_back({-1,0});
			//dir[x].push_back({0,1});
			//dir[x].push_back({0,-1});
		//}
	//}
	
	//memset(memo,-1,sizeof(memo));
	//int counter=0;
	//for(int x=0;x<n;x++){
		//for(int y=0;y<m;y++){
			//if(arr[x][y]=='#') continue;
			//int add=dp(0,x,y);
			////show3(x,x,y,y,add,add);
			//counter+=add;
		//}
	//}
	//cout << counter;
	
	int n,m,k;
	cin >> n >> m >> k;
	
	string arr[n];
	for(int x=0;x<n;x++){
		cin >> arr[x];
	}
	
	string s;
	cin >> s;
	
	bitset<1005000>bs;
	bitset<1005000>check;
	
	int offset=1001;
	for(int x=0;x<n;x++){
		for(int y=0;y<m;y++){
			if(arr[x][y]=='.'){
				check[x*offset+y]=1;
			}
		}
	}
	
	//cout << check.count() << " check\n";
	
	bs|=check;
	
	for(int x=0;x<k;x++){
		if(s[x]=='N'){
			bs>>=offset;
		}
		else if(s[x]=='S'){
			bs<<=offset;
		}
		else if(s[x]=='E'){
			bs<<=1;
		}
		else if(s[x]=='W'){
			bs>>=1;
		}
		else{
			bs=((bs>>offset)|(bs<<offset)|(bs<<1)|(bs>>1));
		}
		bs&=check;
	}
	
	int counter=0;
	for(int x=0;x<n;x++){
		for(int y=0;y<m;y++){
			if(bs[x*offset+y]==1) counter++;
		}
	}
	
	cout << counter;
}
 
int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	//freopen("redistricting.in", "r", stdin);
	//freopen("redistricting.out", "w", stdout);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...