#include <bits/stdc++.h>
using namespace std;
struct bitMatrix {
bitset<500> a[500];
int n, m;
bitMatrix() {}
bitMatrix(int n, int m) : n(n), m(m) {}
bitMatrix(vector<vector<bool>> st) {
n = (int)st.size();
m = (int)st[0].size();
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
a[i][j] = st[i][j];
}
void move_up() {
for (int i = 0; i < n - 1; i++)
swap(a[i], a[i + 1]);
a[n - 1].reset();
}
void move_down() {
for (int i = n - 1; i > 0; i--)
swap(a[i - 1], a[i]);
a[0].reset();
}
void move_left() {
for (int i = 0; i < n; i++)
a[i] >>= 1;
}
void move_right() {
for (int i = 0; i < n; i++)
a[i] <<= 1;
}
void print() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
cout << a[i][j];
cout << '\n';
}
cout << '\n';
}
};
bitMatrix OR(const bitMatrix &a, const bitMatrix &b) {
assert(a.n == b.n && a.m == b.m);
bitMatrix res = a;
for (int i = 0; i < res.n; i++)
res.a[i] = res.a[i] | b.a[i];
return res;
}
bitMatrix AND(const bitMatrix &a, const bitMatrix &b) {
assert(a.n == b.n && a.m == b.m);
bitMatrix res = a;
for (int i = 0; i < res.n; i++)
res.a[i] = res.a[i] & b.a[i];
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, L;
cin >> n >> m >> L;
bitMatrix a(n, m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
char c;
cin >> c;
a.a[i][j] = (c == '.');
}
bitMatrix cur = a;
for (int it = 0; it < L; it++) {
char dir;
cin >> dir;
bitMatrix b(n, m);
if (dir == 'N' || dir == '?') {
bitMatrix c = cur;
c.move_up();
b = OR(b, c);
}
if (dir == 'S' || dir == '?') {
bitMatrix c = cur;
c.move_down();
b = OR(b, c);
}
if (dir == 'W' || dir == '?') {
bitMatrix c = cur;
c.move_left();
b = OR(b, c);
}
if (dir == 'E' || dir == '?') {
bitMatrix c = cur;
c.move_right();
b = OR(b, c);
}
cur = AND(b, a);
}
int ans = 0;
for (int i = 0; i < n; i++)
ans += cur.a[i].count();
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
105 ms |
348 KB |
Output is correct |
23 |
Correct |
106 ms |
604 KB |
Output is correct |
24 |
Correct |
109 ms |
348 KB |
Output is correct |
25 |
Correct |
105 ms |
348 KB |
Output is correct |
26 |
Correct |
104 ms |
600 KB |
Output is correct |
27 |
Correct |
157 ms |
604 KB |
Output is correct |
28 |
Correct |
154 ms |
600 KB |
Output is correct |
29 |
Correct |
138 ms |
604 KB |
Output is correct |
30 |
Correct |
154 ms |
604 KB |
Output is correct |
31 |
Correct |
161 ms |
604 KB |
Output is correct |
32 |
Correct |
188 ms |
604 KB |
Output is correct |
33 |
Correct |
182 ms |
604 KB |
Output is correct |
34 |
Correct |
197 ms |
600 KB |
Output is correct |
35 |
Correct |
204 ms |
604 KB |
Output is correct |
36 |
Correct |
192 ms |
604 KB |
Output is correct |