#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
const int MAXN = 505;
bitset<MAXN> dp[2][MAXN], arr[MAXN];
void solve() {
int n, m, slen;
cin >> n >> m >> slen;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
arr[i].set(j, s[j] == '.');
}
}
string s;
cin >> s;
int pind = 0, cind = 1;
for (int i = 0; i < n; i++) {
dp[cind][i].set();
dp[cind][i] &= arr[i];
}
for (auto& c : s) {
swap(pind, cind);
for (auto& a : dp[cind]) {
a.reset();
}
auto up = [&]() -> void {
for (int i = 0; i < n - 1; i++) {
dp[cind][i] |= dp[pind][i + 1];
}
};
auto down = [&]() -> void {
for (int i = 1; i < n; i++) {
dp[cind][i] |= dp[pind][i - 1];
}
};
auto left = [&]() -> void {
for (int i = 0; i < n; i++) {
dp[cind][i] |= dp[pind][i] >> 1;
}
};
auto right = [&]() -> void {
for (int i = 0; i < n; i++) {
dp[cind][i] |= dp[pind][i] << 1;
}
};
if (c == 'N') {
up();
} else if (c == 'S') {
down();
} else if (c == 'E') {
right();
} else if (c == 'W') {
left();
} else {
assert(c == '?');
up();
down();
left();
right();
}
for (int i = 0; i < n; i++) {
dp[cind][i] &= arr[i];
}
}
int ans = 0;
for (auto& a : dp[cind]) {
ans += int(a.count());
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 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 |
336 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 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 |
336 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 |
75 ms |
596 KB |
Output is correct |
23 |
Correct |
73 ms |
672 KB |
Output is correct |
24 |
Correct |
72 ms |
728 KB |
Output is correct |
25 |
Correct |
73 ms |
720 KB |
Output is correct |
26 |
Correct |
74 ms |
596 KB |
Output is correct |
27 |
Correct |
104 ms |
592 KB |
Output is correct |
28 |
Correct |
108 ms |
668 KB |
Output is correct |
29 |
Correct |
107 ms |
668 KB |
Output is correct |
30 |
Correct |
110 ms |
668 KB |
Output is correct |
31 |
Correct |
103 ms |
596 KB |
Output is correct |
32 |
Correct |
132 ms |
716 KB |
Output is correct |
33 |
Correct |
132 ms |
676 KB |
Output is correct |
34 |
Correct |
136 ms |
716 KB |
Output is correct |
35 |
Correct |
132 ms |
668 KB |
Output is correct |
36 |
Correct |
138 ms |
716 KB |
Output is correct |