#include <bits/stdc++.h>
using namespace std;
#define Task ""
struct __Init__ {
__Init__() {
cin.tie(nullptr)->sync_with_stdio(false);
if (fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout); }
}
} __init__;
using ll = long long;
#ifdef LOCAL
//#define debug(x) cerr << "[" #x " = " << x << "]\n";
#include "debugger.h"
#else
#define debug(...)
#endif // LOCAL
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
template<class C> int isz(const C& c) { return c.size(); }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
constexpr int eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
/// ============================================================================
constexpr int maxN = 512;
constexpr int maxS = 5000 + 5;
int n, m, ns;
char a[maxN][maxN];
char s[maxS];
bitset<maxN> pre[maxN];
bitset<maxN> cur[maxN];
bitset<maxN> nxt[maxN];
signed main() {
cin >> n >> m >> ns;
Rep (i, n) {
cin >> a[i];
Rep (j, m) {
if (a[i][j] == '.') {
pre[i].set(j);
}
}
cur[i] = pre[i];
}
cin >> s;
Rep (_, ns) {
char c = s[_];
Rep (i, n) nxt[i].reset();
if (c == 'N' || c == '?') {
Rep (i, n - 1) {
nxt[i] |= cur[i + 1];
}
}
if (c == 'E' || c == '?') {
Rep (i, n) {
nxt[i] |= (cur[i] << 1);
}
}
if (c == 'S' || c == '?') {
Rep (i, n - 1) {
nxt[i + 1] |= cur[i];
}
}
if (c == 'W' || c == '?') {
Rep (i, n) {
nxt[i] |= (cur[i] >> 1);
}
}
Rep (i, n) {
cur[i] = nxt[i] & pre[i];
}
}
int ans = 0;
Rep (i, n) ans += cur[i].count();
cout << ans << '\n';
}
/**
**/
Compilation message
nautilus.cpp: In constructor '__Init__::__Init__()':
nautilus.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:12:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen(Task".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
460 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 |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
93 ms |
904 KB |
Output is correct |
23 |
Correct |
95 ms |
904 KB |
Output is correct |
24 |
Correct |
96 ms |
908 KB |
Output is correct |
25 |
Correct |
92 ms |
904 KB |
Output is correct |
26 |
Correct |
104 ms |
884 KB |
Output is correct |
27 |
Correct |
128 ms |
904 KB |
Output is correct |
28 |
Correct |
126 ms |
848 KB |
Output is correct |
29 |
Correct |
134 ms |
908 KB |
Output is correct |
30 |
Correct |
139 ms |
832 KB |
Output is correct |
31 |
Correct |
125 ms |
884 KB |
Output is correct |
32 |
Correct |
153 ms |
908 KB |
Output is correct |
33 |
Correct |
157 ms |
904 KB |
Output is correct |
34 |
Correct |
170 ms |
968 KB |
Output is correct |
35 |
Correct |
151 ms |
904 KB |
Output is correct |
36 |
Correct |
158 ms |
844 KB |
Output is correct |