//bit chass 1
#include <bits/stdc++.h>
#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int N = 3e5 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18;
const double P = 3.14;
string s[505];
string a;
int r, c, m;
int ans;
void solve() {
cin >> r >> c >> m;
bitset<500> b[r], bad[r], re, down[r], up[r], left[r], right[r];
for (int i = 0; i < 500; i++)
re[i] = 0;
for (int i = 0; i < r; i++) {
cin >> s[i];
b[i] = bad[i] = re;
for (int j = 0; j < c; j++) {
b[i][j] = (s[i][j] == '.');
bad[i][j] = (s[i][j] == '.');
}
}
cin >> a;
for (int k = 0; k < m; k++) {
// for (int i = 0; i < c; i++)
// cout << b[0][i];
// cout << el;
if (a[k] == 'W') {
for (int i = 0; i < r; i++) {
b[i] = (b[i] >> 1);
b[i] = b[i] & bad[i];
}
}
if (a[k] == 'E') {
for (int i = 0; i < r; i++) {
b[i] = (b[i] << 1);
b[i] = b[i] & bad[i];
}
}
if (a[k] == 'N') {
for (int i = 0; i < r - 1; i++) {
b[i] = b[i + 1] & bad[i];
}
b[r - 1] = re;
}
if (a[k] == 'S') {
for (int i = r - 1; i > 0; i--) {
b[i] = b[i - 1] & bad[i];
}
b[0] = re;
}
if (a[k] == '?') {
up[0] = re;
down[r - 1] = re;
for (int i = 0; i < r; i++) {
if (i != 0)
up[i] = b[i - 1];
if (i != r - 1)
down[i] = b[i + 1];
left[i] = (b[i] >> 1);
right[i] = (b[i] << 1);
}
for (int i = 0; i < r; i++) {
b[i] = (((up[i] | down[i]) | right[i]) | left[i]);
b[i] = b[i] & bad[i];
}
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++)
if (b[i][j])
ans++;
}
cout << ans;
}
int main() {
ibase;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
// cout << "Case " << i << ": ";
solve();
cout << el;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 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 |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
276 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 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 |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
276 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
106 ms |
716 KB |
Output is correct |
23 |
Correct |
102 ms |
716 KB |
Output is correct |
24 |
Correct |
99 ms |
756 KB |
Output is correct |
25 |
Correct |
113 ms |
760 KB |
Output is correct |
26 |
Correct |
106 ms |
764 KB |
Output is correct |
27 |
Correct |
135 ms |
756 KB |
Output is correct |
28 |
Correct |
135 ms |
760 KB |
Output is correct |
29 |
Correct |
141 ms |
760 KB |
Output is correct |
30 |
Correct |
144 ms |
716 KB |
Output is correct |
31 |
Correct |
145 ms |
764 KB |
Output is correct |
32 |
Correct |
163 ms |
756 KB |
Output is correct |
33 |
Correct |
173 ms |
760 KB |
Output is correct |
34 |
Correct |
168 ms |
764 KB |
Output is correct |
35 |
Correct |
170 ms |
760 KB |
Output is correct |
36 |
Correct |
163 ms |
760 KB |
Output is correct |