// _| _|
// _| _| _| _| _|_| _|_|_| _|_|_| _| _| _|_| _|_|
// _|_| _| _| _|_|_|_| _| _| _|_| _|_| _|_|_|_| _|_|_|_|
// _| _| _| _| _| _| _| _|_| _| _| _| _|
// _| _| _|_|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|
// _| _|
// _|_| _|
#include <iostream>
#include <bitset>
#include <vector>
using namespace std;
// #define DEBUG
#ifdef DEBUG
#define dassert(x) assert(x);
#define df(...) printf(__VA_ARGS__)
#else
#define dassert(x)
#define df(...)
#endif
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define ir(x, a, b) ((a) <= (x) && (x) <= (b))
#define vec vector
#define sz(x) (ll)x.size()
#define foru(i, n) for (int i = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()
typedef int64_t ll;
int read() {
int n = 0; bool b = 0; char c = getchar();
for (; !ir(c, '0', '9'); c = getchar()) b = (c == '-');
for (; ir(c, '0', '9'); c = getchar()) n = 10*n + (c-'0');
if (b) return -n;
return n;
}
const int N = 502;
// const int N = 20;
int n, m, k;
struct area {
vec<bitset<N>> v;
area() {
v.resize(n+2);
}
void operator &=(const area& other) {
foru (i, n+2) {
v[i] &= other.v[i];
}
}
void operator |=(const area& other) {
foru (i, n+2) {
v[i] |= other.v[i];
}
}
int count() {
int s = 0;
for (auto& b : v) {
s += b.count();
}
return s;
}
};
area movey(const area& src, int by) {
area a;
for (int i = 1; i <= n; ++i) {
a.v[i] = src.v[i+by];
}
return a;
}
area movex(area a, int by) {
for (int i = 1; i <= n; ++i) {
if (by < 0) {
a.v[i] <<= -by;
} else {
a.v[i] >>= by;
}
}
// for (int i = 0; i <= n+1; ++i) {
// cout << a.v[i] << "\n";
// }
// cout << "\n";
return a;
}
int main() {
df("debug mode\n");
#ifndef DEBUG
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
cin >> n >> m >> k;
area a;
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
for (int j = 1; j <= m; ++j) {
a.v[i][j] = (s[j-1] == '.');
}
}
area full;
// foru (i, m+2) foru (j, m+2) full.v[i][j] = 1;
string s;
cin >> s;
// foru (i, m+2) {
// a.v[0][i] = a.v[n+1][i] = 1;
// }
// foru (i, n+2) {
// a.v[i][0] = a.v[i][m+1] = 1;
// }
const area orig = a;
// for (int i = 0; i <= n+1; ++i) {
// cout << a.v[i] << "\n";
// }
// cout << "\n";
for (int i = 0; i <= k-1; ++i) {
char c = s[i];
area aa = orig;
if (c == 'N') {
aa &= movey(a, 1);
} else if (c == 'S') {
aa &= movey(a, -1);
} else if (c == 'E') {
aa &= movex(a, -1);
} else if (c == 'W') {
aa &= movex(a, 1);
} else if (c == '?') {
area b = movey(a, 1);
b |= movey(a, -1);
b |= movex(a, 1);
b |= movex(a, -1);
aa &= b;
}
a = aa;
#ifdef DEBUG
// for (int i = 0; i <= n+1; ++i) {
// cout << a.v[i] << "\n";
// }
// cout << "\n";
#endif
}
cout << a.count() << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
77 ms |
724 KB |
Output is correct |
23 |
Correct |
78 ms |
736 KB |
Output is correct |
24 |
Correct |
74 ms |
728 KB |
Output is correct |
25 |
Correct |
75 ms |
768 KB |
Output is correct |
26 |
Correct |
70 ms |
720 KB |
Output is correct |
27 |
Correct |
107 ms |
764 KB |
Output is correct |
28 |
Correct |
106 ms |
724 KB |
Output is correct |
29 |
Correct |
106 ms |
768 KB |
Output is correct |
30 |
Correct |
105 ms |
732 KB |
Output is correct |
31 |
Correct |
103 ms |
724 KB |
Output is correct |
32 |
Correct |
134 ms |
768 KB |
Output is correct |
33 |
Correct |
136 ms |
768 KB |
Output is correct |
34 |
Correct |
129 ms |
776 KB |
Output is correct |
35 |
Correct |
131 ms |
724 KB |
Output is correct |
36 |
Correct |
128 ms |
776 KB |
Output is correct |