#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
const int N = 503;
bitset<N> dp[N];
bitset<N> blocks[N];
bitset<N> ndp[N];
void solve(){
int n, m, k;
cin >> n >> m >> k;
for(int i=1; i<=n; i++){
for(int j=m; j>=1; j--){
char c;
cin >> c;
if(c=='.'){
blocks[i][j]=1;
dp[i][j]=1;
}
}
}
string s;
cin >> s;
for(int j=0; j< k; j++){
if(s[j]=='?'){
for(int i=1; i<=n; i++){
ndp[i]=(dp[i]<<1)|(dp[i]>>1)|(dp[i-1])|(dp[i+1]);
}
}
else{
for(int i=1; i<=n; i++){
if(s[j]=='W'){
ndp[i]=dp[i]<<1;
}
if(s[j]=='E'){
ndp[i]=dp[i]>>1;
}
if(s[j]=='S'){
ndp[i]=dp[i-1];
}
if(s[j]=='N'){
ndp[i]=dp[i+1];
}
}
}
for(int i=0; i<=n+1; i++){
ndp[i]&=blocks[i];
}
for(int i=1; i<=n; i++){
dp[i]=ndp[i];
}
}
int ans=0;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
ans+=dp[i][j];
}
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
60 ms |
600 KB |
Output is correct |
23 |
Correct |
63 ms |
788 KB |
Output is correct |
24 |
Correct |
61 ms |
600 KB |
Output is correct |
25 |
Correct |
60 ms |
848 KB |
Output is correct |
26 |
Correct |
59 ms |
728 KB |
Output is correct |
27 |
Correct |
101 ms |
604 KB |
Output is correct |
28 |
Correct |
103 ms |
604 KB |
Output is correct |
29 |
Correct |
103 ms |
604 KB |
Output is correct |
30 |
Correct |
103 ms |
600 KB |
Output is correct |
31 |
Correct |
101 ms |
604 KB |
Output is correct |
32 |
Correct |
132 ms |
792 KB |
Output is correct |
33 |
Correct |
136 ms |
796 KB |
Output is correct |
34 |
Correct |
135 ms |
604 KB |
Output is correct |
35 |
Correct |
141 ms |
604 KB |
Output is correct |
36 |
Correct |
133 ms |
776 KB |
Output is correct |