#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=5e3+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]|(dp[!x][j]<<1));
if(s[i]=='?'||s[i]=='W')
for(int j=1; j<=n; j++)
dp[x][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]|dp[!x][j+1]);
if(s[i]=='?'||s[i]=='S')
for(int j=2; j<=n; j++)
dp[x][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";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
472 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
4 ms |
472 KB |
Output is correct |
4 |
Correct |
6 ms |
460 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
472 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
4 ms |
472 KB |
Output is correct |
4 |
Correct |
6 ms |
460 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
464 KB |
Output is correct |
7 |
Correct |
6 ms |
544 KB |
Output is correct |
8 |
Correct |
9 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
536 KB |
Output is correct |
10 |
Correct |
7 ms |
460 KB |
Output is correct |
11 |
Correct |
9 ms |
464 KB |
Output is correct |
12 |
Correct |
9 ms |
528 KB |
Output is correct |
13 |
Correct |
10 ms |
532 KB |
Output is correct |
14 |
Correct |
9 ms |
460 KB |
Output is correct |
15 |
Correct |
10 ms |
460 KB |
Output is correct |
16 |
Correct |
9 ms |
460 KB |
Output is correct |
17 |
Correct |
12 ms |
524 KB |
Output is correct |
18 |
Correct |
16 ms |
532 KB |
Output is correct |
19 |
Correct |
11 ms |
532 KB |
Output is correct |
20 |
Correct |
11 ms |
528 KB |
Output is correct |
21 |
Correct |
11 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
472 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
4 ms |
472 KB |
Output is correct |
4 |
Correct |
6 ms |
460 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
464 KB |
Output is correct |
7 |
Correct |
6 ms |
544 KB |
Output is correct |
8 |
Correct |
9 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
536 KB |
Output is correct |
10 |
Correct |
7 ms |
460 KB |
Output is correct |
11 |
Correct |
9 ms |
464 KB |
Output is correct |
12 |
Correct |
9 ms |
528 KB |
Output is correct |
13 |
Correct |
10 ms |
532 KB |
Output is correct |
14 |
Correct |
9 ms |
460 KB |
Output is correct |
15 |
Correct |
10 ms |
460 KB |
Output is correct |
16 |
Correct |
9 ms |
460 KB |
Output is correct |
17 |
Correct |
12 ms |
524 KB |
Output is correct |
18 |
Correct |
16 ms |
532 KB |
Output is correct |
19 |
Correct |
11 ms |
532 KB |
Output is correct |
20 |
Correct |
11 ms |
528 KB |
Output is correct |
21 |
Correct |
11 ms |
492 KB |
Output is correct |
22 |
Execution timed out |
1038 ms |
1476 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |