#include<bits/stdc++.h>
using namespace std;
const int mx=505;
typedef long long ll;
int mod=998244353 ;
const int MXm=22;
#define F first
#define S second
const int inf=1e9+10;
bitset<mx> dp[mx];
bitset<mx> dp2[mx];//the previous
bitset<mx>row[mx];
char ss[mx][mx];
string s;
void solve(){
int n,m,k;
cin>>n>>m>>k;
for(int i =0;i<n;i++){
for(int j=0;j<m;j++){
cin>>ss[i][j];
if(ss[i][j]=='.'){
dp[i][j]=1;
row[i][j]=1;
}
}
}
cin>>s;
for(int i=1;i<=k;i++){
for(int i=0;i<n;i++){
dp2[i]=dp[i];
dp[i]&=0;
}
if(s[i-1]=='N'||s[i-1]=='?'){
for(int j=0;j<n;j++){
dp[j]|=(dp2[j+1]&row[j]);
}
}
if(s[i-1]=='S'||s[i-1]=='?'){
for(int j=1;j<n;j++){
dp[j]|=(dp2[j-1]&row[j]);
}
}
if(s[i-1]=='E'||s[i-1]=='?'){
for(int j=0;j<n;j++){
dp[j]|=((dp2[j]<<1)&row[j]);
}
}
if(s[i-1]=='W'||s[i-1]=='?'){
for(int j=0;j<n;j++){
dp[j]|=((dp2[j]>>1)&row[j]);
}
}
}
ll ans=0;
for(int i =0;i<n;i++){
ans+=dp[i].count();
}
cout<<ans;
return;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;t=1;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
380 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 |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
380 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
356 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
380 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
356 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
117 ms |
672 KB |
Output is correct |
23 |
Correct |
86 ms |
844 KB |
Output is correct |
24 |
Correct |
96 ms |
844 KB |
Output is correct |
25 |
Correct |
83 ms |
844 KB |
Output is correct |
26 |
Correct |
85 ms |
884 KB |
Output is correct |
27 |
Correct |
139 ms |
844 KB |
Output is correct |
28 |
Correct |
144 ms |
912 KB |
Output is correct |
29 |
Correct |
140 ms |
908 KB |
Output is correct |
30 |
Correct |
153 ms |
968 KB |
Output is correct |
31 |
Correct |
136 ms |
884 KB |
Output is correct |
32 |
Correct |
165 ms |
844 KB |
Output is correct |
33 |
Correct |
188 ms |
904 KB |
Output is correct |
34 |
Correct |
170 ms |
904 KB |
Output is correct |
35 |
Correct |
162 ms |
956 KB |
Output is correct |
36 |
Correct |
161 ms |
844 KB |
Output is correct |