#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=5e2+10;
int n, m, k;
string curr, s;
bitset<MAX>dp[2][MAX], p[MAX];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>m>>k;
for(int i=1; i<=n; i++){
cin>>curr;
for(int j=1; j<=m; j++)
if(curr[j-1]=='.')
p[i][j]=dp[1][i][j]=1;
}
cin>>s;
s='$'+s;
int x=0;
for(int i=1; i<=k; i++){
for(int j=1; j<=n; j++)
dp[x][j]&=0;
if(s[i]=='?'||s[i]=='E')
for(int j=1; j<=n; j++)
dp[x][j]|=(dp[!x][j]<<1);
if(s[i]=='?'||s[i]=='W')
for(int j=1; j<=n; j++)
dp[x][j]|=(dp[!x][j]>>1);
if(s[i]=='?'||s[i]=='N')
for(int j=n-1; j>=1; j--)
dp[x][j]|=dp[!x][j+1];
if(s[i]=='?'||s[i]=='S')
for(int j=2; j<=n; j++)
dp[x][j]|=dp[!x][j-1];
for(int j=1; j<=n; j++)
dp[x][j]&=p[j];
x=!x;
}
int wynik=0;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
wynik+=dp[!x][i][j];
cout<<wynik<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
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 |
324 KB |
Output is correct |
6 |
Correct |
1 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 |
324 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 |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
320 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 |
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 |
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 |
324 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 |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
320 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 |
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 |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
108 ms |
660 KB |
Output is correct |
23 |
Correct |
82 ms |
652 KB |
Output is correct |
24 |
Correct |
83 ms |
660 KB |
Output is correct |
25 |
Correct |
81 ms |
656 KB |
Output is correct |
26 |
Correct |
82 ms |
632 KB |
Output is correct |
27 |
Correct |
123 ms |
660 KB |
Output is correct |
28 |
Correct |
122 ms |
564 KB |
Output is correct |
29 |
Correct |
132 ms |
588 KB |
Output is correct |
30 |
Correct |
145 ms |
656 KB |
Output is correct |
31 |
Correct |
115 ms |
576 KB |
Output is correct |
32 |
Correct |
160 ms |
704 KB |
Output is correct |
33 |
Correct |
161 ms |
660 KB |
Output is correct |
34 |
Correct |
159 ms |
656 KB |
Output is correct |
35 |
Correct |
162 ms |
656 KB |
Output is correct |
36 |
Correct |
165 ms |
708 KB |
Output is correct |