#include<bits/stdc++.h>
using namespace std;
bitset<501>dp[2][509];
bitset<501>a[509];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("usaco.INP","r",stdin);
//freopen("usaco.OUT","w",stdout);
int n,m,k;
cin>>n>>m>>k;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
char r;
cin>>r;
if (r=='.')dp[0][i][j]=a[i][j]=1;
}
}
string s;
cin>>s;
s=" "+s;
for (int i=1;i<=k;i++){
if (s[i]=='?'){
for (int j=1;j<=n;j++){
dp[1][j]=((dp[0][j-1])|(dp[0][j+1])|(dp[0][j]>>1)|(dp[0][j]<<1));
}
}
else if (s[i]=='N'){//up
for (int j=1;j<=n;j++){
dp[1][j]|=(dp[0][j+1]);
}
}
else if (s[i]=='E'){//right
for (int j=1;j<=n;j++){
dp[1][j]|=(dp[0][j]<<1);
}
}
else if (s[i]=='S'){//down
for (int j=1;j<=n;j++){
dp[1][j]|=(dp[0][j-1]);
}
}
else if (s[i]=='W'){//left
for (int j=1;j<=n;j++){
dp[1][j]|=(dp[0][j]>>1);
}
}
for (int j=1;j<=n;j++){
dp[1][j]&=a[j];
dp[0][j]=dp[1][j];
dp[1][j].reset();
}
}
int ans=0;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
if (dp[0][i][j]){
ans++;
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
356 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
352 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
356 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
352 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
356 KB |
Output is correct |
22 |
Correct |
110 ms |
680 KB |
Output is correct |
23 |
Correct |
111 ms |
684 KB |
Output is correct |
24 |
Correct |
107 ms |
672 KB |
Output is correct |
25 |
Correct |
112 ms |
676 KB |
Output is correct |
26 |
Correct |
104 ms |
656 KB |
Output is correct |
27 |
Correct |
168 ms |
660 KB |
Output is correct |
28 |
Correct |
168 ms |
672 KB |
Output is correct |
29 |
Correct |
161 ms |
664 KB |
Output is correct |
30 |
Correct |
168 ms |
668 KB |
Output is correct |
31 |
Correct |
164 ms |
596 KB |
Output is correct |
32 |
Correct |
204 ms |
672 KB |
Output is correct |
33 |
Correct |
201 ms |
668 KB |
Output is correct |
34 |
Correct |
208 ms |
660 KB |
Output is correct |
35 |
Correct |
212 ms |
668 KB |
Output is correct |
36 |
Correct |
201 ms |
656 KB |
Output is correct |