#include <bits/stdc++.h>
using namespace std;
const int D[4][2] = {{0,-1},{0,1},{-1,0},{1,0}};
const int NROW = 507;
const int NCOL = 507;
const int N = 5007;
int numRow, numCol, n;
bitset<NCOL> ans[NROW], tmp[NROW], islands[NROW];
int res;
void process(char c) {
if (c == 'W') {
for (int i = 1; i <= numRow; ++i) {
ans[i] = (ans[i]>>1) & islands[i];
}
}
else if (c == 'E') {
for (int i = 1; i <= numRow; ++i) {
ans[i] = (ans[i]<<1) & islands[i];
}
}
else if (c == 'N') {
for (int i = 1; i <= numRow; ++i) {
ans[i] = ans[i+1] & islands[i];
}
}
else if (c == 'S') {
for (int i = numRow; i >= 1; --i) {
ans[i] = ans[i-1] & islands[i];
}
}
else {
for (int i = 1; i <= numRow; ++i) {
tmp[i] = ((ans[i]>>1) | (ans[i]<<1) | ans[i-1] | ans[i+1]) & islands[i];
}
for (int i = 1; i <= numRow; ++i) {
ans[i] = tmp[i];
}
}
// for (int i = 1; i <= numRow; ++i, cerr << '\n')
// for (int j = 1; j <= numCol; ++j) cerr << ans[i][j];
// cerr << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
// freopen("NAUTILUS.inp", "r", stdin);
// freopen("NAUTILUS.out", "w", stdout);
cin >> numRow >> numCol >> n;
for (int i = 1; i <= numRow; ++i)
for (int j = 1; j <= numCol; ++j) {
char c; cin >> c;
islands[i][j] = c == '.';
ans[i][j] = c == '.';
}
// for (int i = 1; i <= numRow; ++i, cerr << '\n')
// for (int j = 1; j <= numCol; ++j) cerr << ans[i][j];
// cerr << '\n';
for (int i = 1; i <= n; ++i) {
char c; cin >> c;
process(c);
}
for (int i = 1; i <= numRow; ++i)
for (int j = 1; j <= numCol; ++j) {
res += ans[i][j];
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 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 |
2 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 |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 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 |
2 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 |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
84 ms |
388 KB |
Output is correct |
23 |
Correct |
84 ms |
332 KB |
Output is correct |
24 |
Correct |
82 ms |
384 KB |
Output is correct |
25 |
Correct |
99 ms |
588 KB |
Output is correct |
26 |
Correct |
84 ms |
708 KB |
Output is correct |
27 |
Correct |
140 ms |
640 KB |
Output is correct |
28 |
Correct |
144 ms |
588 KB |
Output is correct |
29 |
Correct |
142 ms |
644 KB |
Output is correct |
30 |
Correct |
146 ms |
640 KB |
Output is correct |
31 |
Correct |
140 ms |
636 KB |
Output is correct |
32 |
Correct |
190 ms |
576 KB |
Output is correct |
33 |
Correct |
182 ms |
572 KB |
Output is correct |
34 |
Correct |
190 ms |
636 KB |
Output is correct |
35 |
Correct |
192 ms |
576 KB |
Output is correct |
36 |
Correct |
182 ms |
636 KB |
Output is correct |