#include<bits/stdc++.h>
using namespace std;
const int N = 501;
int main() {
int n, m, k;
cin >> n >> m >> k;
bitset<N> dp[2][1 + N];
bitset<N> grid[1 + N];
for(int i = 1; i <= n; i++){
for(int j = 0; j < m; j++){
char c;
cin >> c;
if(c == '.'){
grid[i].set(j, 1);
dp[0][i].set(j, 1);
}
else{
grid[i].set(j, 0);
dp[0][i].set(j, 0);
}
}
}
string s;
cin >> s;
for(int i = 1; i <= k; i++){
for(int j = 1; j <= n; j++){
if(s[i - 1] == 'W'){
dp[i % 2][j] = grid[j] & (dp[1 - i % 2][j] >> 1);
}
else if(s[i - 1] == 'E'){
dp[i % 2][j] = grid[j] & (dp[1 - i % 2][j] << 1);
}
else if(s[i - 1] == 'N'){
dp[i % 2][j] = grid[j] & dp[1 - i % 2][j + 1];
}
else if(s[i - 1] == 'S'){
dp[i % 2][j] = grid[j] & dp[1 - i % 2][j - 1];
}
else{
dp[i % 2][j] = grid[j] & ((dp[1 - i % 2][j] >> 1) | (dp[1 - i % 2][j] << 1) | (dp[1 - i % 2][j + 1]) | (dp[1 - i % 2][j - 1]));
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
ans += dp[k % 2][i].count();
}
cout << ans << "\n";
}
# |
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 |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
536 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
420 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 |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
536 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
420 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
80 ms |
768 KB |
Output is correct |
23 |
Correct |
84 ms |
780 KB |
Output is correct |
24 |
Correct |
81 ms |
764 KB |
Output is correct |
25 |
Correct |
80 ms |
604 KB |
Output is correct |
26 |
Correct |
78 ms |
604 KB |
Output is correct |
27 |
Correct |
113 ms |
768 KB |
Output is correct |
28 |
Correct |
115 ms |
600 KB |
Output is correct |
29 |
Correct |
116 ms |
604 KB |
Output is correct |
30 |
Correct |
115 ms |
604 KB |
Output is correct |
31 |
Correct |
113 ms |
772 KB |
Output is correct |
32 |
Correct |
145 ms |
1008 KB |
Output is correct |
33 |
Correct |
141 ms |
764 KB |
Output is correct |
34 |
Correct |
146 ms |
604 KB |
Output is correct |
35 |
Correct |
144 ms |
600 KB |
Output is correct |
36 |
Correct |
140 ms |
764 KB |
Output is correct |