#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
using ll = long long;
const int mod = 1e9+7;
void solve(int tc) {
int r, c, m;
cin >> r >> c >> m;
const int mxRC = 500 * 500;
bitset<mxRC> cur, can;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
char x;
cin >> x;
can[i*c+j] = cur[i*c+j] = (x == '.');
}
}
bitset<mxRC> lastcol, firstcol;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
firstcol[i*c+j] = j != 0;
lastcol[i*c+j] = j != c-1;
}
}
string s;
cin >> s;
for (char x : s) {
bitset<mxRC> prev = cur;
cur = 0;
if (x == 'S' or x == '?') cur |= (prev << c) & can;
if (x == 'N' or x == '?') cur |= (prev >> c) & can;
if (x == 'E' or x == '?') cur |= (prev << 1) & can & firstcol;
if (x == 'W' or x == '?') cur |= (prev >> 1) & can & lastcol;
}
cout << cur.count() << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
6 ms |
460 KB |
Output is correct |
13 |
Correct |
7 ms |
460 KB |
Output is correct |
14 |
Correct |
6 ms |
460 KB |
Output is correct |
15 |
Correct |
6 ms |
452 KB |
Output is correct |
16 |
Correct |
6 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
460 KB |
Output is correct |
18 |
Correct |
7 ms |
460 KB |
Output is correct |
19 |
Correct |
7 ms |
460 KB |
Output is correct |
20 |
Correct |
7 ms |
564 KB |
Output is correct |
21 |
Correct |
7 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
6 ms |
460 KB |
Output is correct |
13 |
Correct |
7 ms |
460 KB |
Output is correct |
14 |
Correct |
6 ms |
460 KB |
Output is correct |
15 |
Correct |
6 ms |
452 KB |
Output is correct |
16 |
Correct |
6 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
460 KB |
Output is correct |
18 |
Correct |
7 ms |
460 KB |
Output is correct |
19 |
Correct |
7 ms |
460 KB |
Output is correct |
20 |
Correct |
7 ms |
564 KB |
Output is correct |
21 |
Correct |
7 ms |
460 KB |
Output is correct |
22 |
Correct |
166 ms |
796 KB |
Output is correct |
23 |
Correct |
168 ms |
752 KB |
Output is correct |
24 |
Correct |
162 ms |
800 KB |
Output is correct |
25 |
Correct |
164 ms |
796 KB |
Output is correct |
26 |
Correct |
164 ms |
716 KB |
Output is correct |
27 |
Correct |
257 ms |
796 KB |
Output is correct |
28 |
Correct |
266 ms |
792 KB |
Output is correct |
29 |
Correct |
273 ms |
716 KB |
Output is correct |
30 |
Correct |
264 ms |
792 KB |
Output is correct |
31 |
Correct |
257 ms |
800 KB |
Output is correct |
32 |
Correct |
318 ms |
796 KB |
Output is correct |
33 |
Correct |
347 ms |
796 KB |
Output is correct |
34 |
Correct |
325 ms |
756 KB |
Output is correct |
35 |
Correct |
320 ms |
808 KB |
Output is correct |
36 |
Correct |
324 ms |
800 KB |
Output is correct |