#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
133 ms |
644 KB |
Output is correct |
23 |
Correct |
140 ms |
900 KB |
Output is correct |
24 |
Correct |
131 ms |
836 KB |
Output is correct |
25 |
Correct |
131 ms |
908 KB |
Output is correct |
26 |
Correct |
134 ms |
828 KB |
Output is correct |
27 |
Correct |
182 ms |
844 KB |
Output is correct |
28 |
Correct |
188 ms |
900 KB |
Output is correct |
29 |
Correct |
187 ms |
968 KB |
Output is correct |
30 |
Correct |
202 ms |
896 KB |
Output is correct |
31 |
Correct |
181 ms |
968 KB |
Output is correct |
32 |
Correct |
225 ms |
900 KB |
Output is correct |
33 |
Correct |
232 ms |
904 KB |
Output is correct |
34 |
Correct |
224 ms |
896 KB |
Output is correct |
35 |
Correct |
223 ms |
844 KB |
Output is correct |
36 |
Correct |
221 ms |
844 KB |
Output is correct |