#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, m, k;
cin>>n>>m>>k;
char a[n][m];
bitset<502> grid[n];
for(int i= 0;i<n;i++){
bitset<502> b(0);
for(int j= 0;j<m;j++){
cin>>a[i][j];
if(a[i][j] == '.') b[j] = 1;
}
grid[i] = b;
}
string s;
cin>>s;
bitset<502> dp[n+5][k+5];
for(int i= 0;i<n;i++){
dp[i][0] = grid[i];
}
for(int i = 1;i<=k;i++){
for(int j= 0;j<n;j++){
if(s[i-1] == 'N' || s[i-1] == '?'){
if(j != n-1) dp[j][i] |= dp[j+1][i-1] & grid[j];
}
if(s[i-1] == 'E' || s[i-1] == '?'){
dp[j][i] |= (dp[j][i-1] << 1) & grid[j];
}
if(s[i-1] == 'W' || s[i-1] == '?'){
dp[j][i] |= (dp[j][i-1] >> 1) & grid[j];
}
if(s[i-1] == 'S' || s[i-1] == '?'){
if(j > 0) dp[j][i] |= dp[j-1][i-1] & grid[j];
}
}
}
int ans = 0;
for(int j= 0;j<n;j++){
ans += dp[j][k].count();
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1004 KB |
Output is correct |
2 |
Correct |
2 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
1004 KB |
Output is correct |
4 |
Correct |
2 ms |
1004 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1004 KB |
Output is correct |
2 |
Correct |
2 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
1004 KB |
Output is correct |
4 |
Correct |
2 ms |
1004 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
1004 KB |
Output is correct |
8 |
Correct |
2 ms |
1004 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
10 |
Correct |
2 ms |
1004 KB |
Output is correct |
11 |
Correct |
2 ms |
1004 KB |
Output is correct |
12 |
Correct |
2 ms |
1004 KB |
Output is correct |
13 |
Correct |
3 ms |
1004 KB |
Output is correct |
14 |
Correct |
3 ms |
1004 KB |
Output is correct |
15 |
Correct |
2 ms |
1004 KB |
Output is correct |
16 |
Correct |
2 ms |
1004 KB |
Output is correct |
17 |
Correct |
2 ms |
1004 KB |
Output is correct |
18 |
Correct |
2 ms |
1004 KB |
Output is correct |
19 |
Correct |
2 ms |
1004 KB |
Output is correct |
20 |
Correct |
2 ms |
1004 KB |
Output is correct |
21 |
Correct |
2 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1004 KB |
Output is correct |
2 |
Correct |
2 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
1004 KB |
Output is correct |
4 |
Correct |
2 ms |
1004 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
1004 KB |
Output is correct |
8 |
Correct |
2 ms |
1004 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
10 |
Correct |
2 ms |
1004 KB |
Output is correct |
11 |
Correct |
2 ms |
1004 KB |
Output is correct |
12 |
Correct |
2 ms |
1004 KB |
Output is correct |
13 |
Correct |
3 ms |
1004 KB |
Output is correct |
14 |
Correct |
3 ms |
1004 KB |
Output is correct |
15 |
Correct |
2 ms |
1004 KB |
Output is correct |
16 |
Correct |
2 ms |
1004 KB |
Output is correct |
17 |
Correct |
2 ms |
1004 KB |
Output is correct |
18 |
Correct |
2 ms |
1004 KB |
Output is correct |
19 |
Correct |
2 ms |
1004 KB |
Output is correct |
20 |
Correct |
2 ms |
1004 KB |
Output is correct |
21 |
Correct |
2 ms |
1004 KB |
Output is correct |
22 |
Correct |
205 ms |
159212 KB |
Output is correct |
23 |
Correct |
204 ms |
159084 KB |
Output is correct |
24 |
Correct |
208 ms |
159212 KB |
Output is correct |
25 |
Correct |
246 ms |
159084 KB |
Output is correct |
26 |
Correct |
202 ms |
159212 KB |
Output is correct |
27 |
Correct |
297 ms |
159084 KB |
Output is correct |
28 |
Correct |
263 ms |
159084 KB |
Output is correct |
29 |
Correct |
258 ms |
159084 KB |
Output is correct |
30 |
Correct |
293 ms |
159240 KB |
Output is correct |
31 |
Correct |
252 ms |
159340 KB |
Output is correct |
32 |
Correct |
298 ms |
159212 KB |
Output is correct |
33 |
Correct |
299 ms |
159340 KB |
Output is correct |
34 |
Correct |
298 ms |
159084 KB |
Output is correct |
35 |
Correct |
297 ms |
159212 KB |
Output is correct |
36 |
Correct |
311 ms |
159212 KB |
Output is correct |