#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};
const string dd = "SWNE";
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 good = [&](int i, int j) {
return 0 <= i && i < n && 0 <= j && j < m && a[i][j] != '#';
};
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;
}
bool ok = false;
for (int _ = 0; _ < 4; ++_) {
int x = i + dx[_], y = j + dy[_];
if (good(x, y)) {
if ((s[t - 1] == dd[_] || s[t - 1] == '?') && dp[t - 1][x][y]) {
ok = true;
break;
}
}
}
if (ok) {
dp[t][i][j] = 1;
}
}
}
}
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 |
1112 KB |
Output is correct |
2 |
Correct |
18 ms |
1112 KB |
Output is correct |
3 |
Correct |
17 ms |
1116 KB |
Output is correct |
4 |
Correct |
13 ms |
1116 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1112 KB |
Output is correct |
2 |
Correct |
18 ms |
1112 KB |
Output is correct |
3 |
Correct |
17 ms |
1116 KB |
Output is correct |
4 |
Correct |
13 ms |
1116 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
3 ms |
1116 KB |
Output is correct |
7 |
Correct |
9 ms |
1116 KB |
Output is correct |
8 |
Correct |
17 ms |
1368 KB |
Output is correct |
9 |
Correct |
14 ms |
1116 KB |
Output is correct |
10 |
Correct |
6 ms |
1116 KB |
Output is correct |
11 |
Correct |
3 ms |
1116 KB |
Output is correct |
12 |
Correct |
7 ms |
1200 KB |
Output is correct |
13 |
Correct |
11 ms |
1116 KB |
Output is correct |
14 |
Correct |
14 ms |
1208 KB |
Output is correct |
15 |
Correct |
6 ms |
1112 KB |
Output is correct |
16 |
Correct |
3 ms |
1112 KB |
Output is correct |
17 |
Correct |
6 ms |
1208 KB |
Output is correct |
18 |
Correct |
7 ms |
1064 KB |
Output is correct |
19 |
Correct |
8 ms |
1116 KB |
Output is correct |
20 |
Correct |
4 ms |
1112 KB |
Output is correct |
21 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1112 KB |
Output is correct |
2 |
Correct |
18 ms |
1112 KB |
Output is correct |
3 |
Correct |
17 ms |
1116 KB |
Output is correct |
4 |
Correct |
13 ms |
1116 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
3 ms |
1116 KB |
Output is correct |
7 |
Correct |
9 ms |
1116 KB |
Output is correct |
8 |
Correct |
17 ms |
1368 KB |
Output is correct |
9 |
Correct |
14 ms |
1116 KB |
Output is correct |
10 |
Correct |
6 ms |
1116 KB |
Output is correct |
11 |
Correct |
3 ms |
1116 KB |
Output is correct |
12 |
Correct |
7 ms |
1200 KB |
Output is correct |
13 |
Correct |
11 ms |
1116 KB |
Output is correct |
14 |
Correct |
14 ms |
1208 KB |
Output is correct |
15 |
Correct |
6 ms |
1112 KB |
Output is correct |
16 |
Correct |
3 ms |
1112 KB |
Output is correct |
17 |
Correct |
6 ms |
1208 KB |
Output is correct |
18 |
Correct |
7 ms |
1064 KB |
Output is correct |
19 |
Correct |
8 ms |
1116 KB |
Output is correct |
20 |
Correct |
4 ms |
1112 KB |
Output is correct |
21 |
Correct |
3 ms |
1116 KB |
Output is correct |
22 |
Runtime error |
465 ms |
262144 KB |
Execution killed with signal 9 |
23 |
Halted |
0 ms |
0 KB |
- |