#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=510;
bitset<N>t[N];
bitset<N>t2[N];
bitset<N>xd[N];
void solve(){
int n,m,d;
cin>>n>>m>>d;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char a;
cin>>a;
if(a=='.') t[i][j]=1,xd[i][j]=1;
}
}
string s;
cin>>s;
s="#"+s;
for(int j=1;j<=d;j++){
if(s[j]=='W') for(int i=1;i<=n;i++) t[i]>>=1,t[i]&=xd[i];
if(s[j]=='E') for(int i=1;i<=n;i++) t[i]<<=1,t[i]&=xd[i];
if(s[j]=='N'){
for(int i=1;i<n;i++) t[i]=t[i+1],t[i]&=xd[i];
t[n].reset();
}
if(s[j]=='S'){
for(int i=n;i>=2;i--) t[i]=t[i-1],t[i]&=xd[i];
t[1].reset();
}
if(s[j]=='?'){
t2[1].reset();
for(int i=2;i<=n;i++) t2[i]=t[i-1];
for(int i=n-1;i>=1;i--) t2[i]|=t[i+1];
for(int i=1;i<=n;i++) t2[i]|=(t[i]<<1),t2[i]|=(t[i]>>1),t2[i]&=xd[i];
for(int i=1;i<=n;i++) t[i]=t2[i];
}
}
int res=0;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(t[i][j]) res++;
cout<<res<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
320 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 |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
332 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 |
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 |
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 |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
332 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 |
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 |
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 |
320 KB |
Output is correct |
22 |
Correct |
67 ms |
652 KB |
Output is correct |
23 |
Correct |
59 ms |
596 KB |
Output is correct |
24 |
Correct |
61 ms |
660 KB |
Output is correct |
25 |
Correct |
61 ms |
652 KB |
Output is correct |
26 |
Correct |
64 ms |
632 KB |
Output is correct |
27 |
Correct |
104 ms |
588 KB |
Output is correct |
28 |
Correct |
117 ms |
656 KB |
Output is correct |
29 |
Correct |
115 ms |
656 KB |
Output is correct |
30 |
Correct |
112 ms |
656 KB |
Output is correct |
31 |
Correct |
125 ms |
588 KB |
Output is correct |
32 |
Correct |
138 ms |
596 KB |
Output is correct |
33 |
Correct |
144 ms |
656 KB |
Output is correct |
34 |
Correct |
143 ms |
588 KB |
Output is correct |
35 |
Correct |
137 ms |
672 KB |
Output is correct |
36 |
Correct |
139 ms |
644 KB |
Output is correct |