#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;
template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
for (auto &i : a) {
is >> i;
}
return is;
}
const array<int, 4> dx = {-1, 0, 1, 0};
const array<int, 4> dy = {0, 1, 0, -1};
int32_t main() {
#ifdef LOCAL
freopen("/tmp/input.txt", "r", stdin);
#else
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int n, m, k;
cin >> n >> m >> k;
vector<string> a(n);
cin >> a;
string s;
cin >> s;
auto ok = [&](int i, int j) {
return 0 <= i && i < n && 0 <= j && j < m;
};
vector<vector<vector<bool>>> dp(k + 1, vector<vector<bool>>(n, vector<bool>(m)));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] != '#') {
dp[0][i][j] = 1;
}
}
}
for (int t = 1; t <= k; ++t) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] == '#') {
continue;
}
if (s[t - 1] == 'N') {
if (ok(i + 1, j)) {
dp[t][i][j] = (dp[t][i][j] | dp[t - 1][i + 1][j]);
}
} else if (s[t - 1] == 'E') {
if (ok(i, j - 1)) {
dp[t][i][j] = (dp[t][i][j] | dp[t - 1][i][j - 1]);
}
} else if (s[t - 1] == 'S') {
if (ok(i - 1, j)) {
dp[t][i][j] = (dp[t][i][j] | dp[t - 1][i - 1][j]);
}
} else if (s[t - 1] == 'W') {
if (ok(i, j + 1)) {
dp[t][i][j] = (dp[t][i][j] | dp[t - 1][i][j + 1]);
}
} else {
for (int _ = 0; _ < 4; ++_) {
int x = i + dx[_], y = j + dy[_];
if (ok(x, y)) {
dp[t][i][j] = (dp[t][i][j] | dp[t - 1][x][y]);
}
}
}
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (dp[k][i][j]) {
++ans;
}
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1116 KB |
Output is correct |
2 |
Correct |
6 ms |
1108 KB |
Output is correct |
3 |
Correct |
6 ms |
1116 KB |
Output is correct |
4 |
Correct |
6 ms |
1208 KB |
Output is correct |
5 |
Correct |
4 ms |
1276 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1116 KB |
Output is correct |
2 |
Correct |
6 ms |
1108 KB |
Output is correct |
3 |
Correct |
6 ms |
1116 KB |
Output is correct |
4 |
Correct |
6 ms |
1208 KB |
Output is correct |
5 |
Correct |
4 ms |
1276 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
9 ms |
1116 KB |
Output is correct |
8 |
Correct |
9 ms |
1116 KB |
Output is correct |
9 |
Correct |
9 ms |
1116 KB |
Output is correct |
10 |
Correct |
6 ms |
1116 KB |
Output is correct |
11 |
Correct |
3 ms |
1368 KB |
Output is correct |
12 |
Correct |
18 ms |
1116 KB |
Output is correct |
13 |
Correct |
14 ms |
1112 KB |
Output is correct |
14 |
Correct |
12 ms |
1116 KB |
Output is correct |
15 |
Correct |
7 ms |
1116 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
23 ms |
1116 KB |
Output is correct |
18 |
Correct |
17 ms |
1116 KB |
Output is correct |
19 |
Correct |
11 ms |
1116 KB |
Output is correct |
20 |
Correct |
7 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1116 KB |
Output is correct |
2 |
Correct |
6 ms |
1108 KB |
Output is correct |
3 |
Correct |
6 ms |
1116 KB |
Output is correct |
4 |
Correct |
6 ms |
1208 KB |
Output is correct |
5 |
Correct |
4 ms |
1276 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
9 ms |
1116 KB |
Output is correct |
8 |
Correct |
9 ms |
1116 KB |
Output is correct |
9 |
Correct |
9 ms |
1116 KB |
Output is correct |
10 |
Correct |
6 ms |
1116 KB |
Output is correct |
11 |
Correct |
3 ms |
1368 KB |
Output is correct |
12 |
Correct |
18 ms |
1116 KB |
Output is correct |
13 |
Correct |
14 ms |
1112 KB |
Output is correct |
14 |
Correct |
12 ms |
1116 KB |
Output is correct |
15 |
Correct |
7 ms |
1116 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
23 ms |
1116 KB |
Output is correct |
18 |
Correct |
17 ms |
1116 KB |
Output is correct |
19 |
Correct |
11 ms |
1116 KB |
Output is correct |
20 |
Correct |
7 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1008 KB |
Output is correct |
22 |
Runtime error |
491 ms |
262144 KB |
Execution killed with signal 9 |
23 |
Halted |
0 ms |
0 KB |
- |