This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#pra
using namespace std;
const int N=5e2+1;
const int tx[4]={1,-1,0,0};
const int ty[4]={0,0,1,-1};
const char w[5]={'S','N','E','W','?'};
//bool can[2][N][N];
bitset<N>can[2][N];
bitset<N>homo[N];
bitset<N> clr;
char a[N][N];
signed main(){
ios_base::sync_with_stdio(false);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++){
cin>>a[i][j];
}
}
string s;
cin>>s;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]!='#') can[0][i][j]=1,homo[i][j]=1;
}
}
for(int t=0;t<k;t++){
int tp=find(w,w+5,s[t])-w;
// cerr<<tp<<endl;
for(int i=0;i<n;i++) can[1][i].reset();
for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// can[1][i][j]=0;
// if(a[i][j]=='#') {continue;}
for(int x=0;x<4;x++){
if(tp==x || tp==4){
if(x==0) {if(i)can[1][i]|=can[0][i-1];}
else if(x==1){if(i+1<n)can[1][i]|=can[0][i+1];}
else if(x==2) {can[1][i]|=(can[0][i]<<1);}
else if(x==3) {can[1][i]|=(can[0][i]>>1);}
}
}
can[1][i]&=homo[i];
// }
}
swap(can[1],can[0]);
}
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) ans+=can[0][i][j];
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |