#include <bits/stdc++.h>
using namespace std;
#define dbg(x) cerr << #x << ": " << x << endl;
const int MAX_N = 500 + 5;
const int MAX_M = 5000 + 5;
string a[MAX_N];
vector<pair<int, int>> delta = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool dp[MAX_N][MAX_N][MAX_N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, t;
cin >> n >> m >> t;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
string s;
cin >> s;
reverse(s.begin(), s.end());
vector<vector<pair<int, int>>> dir(t);
for (int i = 0; i < t; ++i) {
auto c = s[i];
if (c == 'N') {
dir[i] = {delta[0]};
} else if (c == 'S') {
dir[i] = {delta[1]};
} else if (c == 'W') {
dir[i] = {delta[2]};
} else if (c == 'E') {
dir[i] = {delta[3]};
} else {
dir[i] = delta;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
dp[i][j][t] = (a[i][j] == '#' ? 0 : 1);
}
}
// reverse the operations and check if there exists at least one starting position
for (int k = t - 1; k >= 0; --k) {
for (const auto& [di, dj] : dir[k]) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] == '#') continue;
if (i + di < 0 || i + di >= n || j + dj < 0 || j + dj >= m) continue;
dp[i][j][k] |= dp[i + di][j + dj][k + 1];
}
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
ans += dp[i][j][0];
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5588 KB |
Output is correct |
2 |
Correct |
7 ms |
5692 KB |
Output is correct |
3 |
Correct |
7 ms |
5688 KB |
Output is correct |
4 |
Correct |
7 ms |
5588 KB |
Output is correct |
5 |
Correct |
6 ms |
5588 KB |
Output is correct |
6 |
Correct |
3 ms |
5676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5588 KB |
Output is correct |
2 |
Correct |
7 ms |
5692 KB |
Output is correct |
3 |
Correct |
7 ms |
5688 KB |
Output is correct |
4 |
Correct |
7 ms |
5588 KB |
Output is correct |
5 |
Correct |
6 ms |
5588 KB |
Output is correct |
6 |
Correct |
3 ms |
5676 KB |
Output is correct |
7 |
Correct |
13 ms |
5608 KB |
Output is correct |
8 |
Correct |
10 ms |
5588 KB |
Output is correct |
9 |
Correct |
11 ms |
5588 KB |
Output is correct |
10 |
Correct |
10 ms |
5588 KB |
Output is correct |
11 |
Correct |
4 ms |
5588 KB |
Output is correct |
12 |
Correct |
15 ms |
5692 KB |
Output is correct |
13 |
Correct |
15 ms |
5692 KB |
Output is correct |
14 |
Correct |
16 ms |
5692 KB |
Output is correct |
15 |
Correct |
13 ms |
5716 KB |
Output is correct |
16 |
Correct |
5 ms |
5588 KB |
Output is correct |
17 |
Correct |
19 ms |
5616 KB |
Output is correct |
18 |
Correct |
19 ms |
5692 KB |
Output is correct |
19 |
Correct |
19 ms |
5588 KB |
Output is correct |
20 |
Correct |
15 ms |
5688 KB |
Output is correct |
21 |
Correct |
6 ms |
5588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5588 KB |
Output is correct |
2 |
Correct |
7 ms |
5692 KB |
Output is correct |
3 |
Correct |
7 ms |
5688 KB |
Output is correct |
4 |
Correct |
7 ms |
5588 KB |
Output is correct |
5 |
Correct |
6 ms |
5588 KB |
Output is correct |
6 |
Correct |
3 ms |
5676 KB |
Output is correct |
7 |
Correct |
13 ms |
5608 KB |
Output is correct |
8 |
Correct |
10 ms |
5588 KB |
Output is correct |
9 |
Correct |
11 ms |
5588 KB |
Output is correct |
10 |
Correct |
10 ms |
5588 KB |
Output is correct |
11 |
Correct |
4 ms |
5588 KB |
Output is correct |
12 |
Correct |
15 ms |
5692 KB |
Output is correct |
13 |
Correct |
15 ms |
5692 KB |
Output is correct |
14 |
Correct |
16 ms |
5692 KB |
Output is correct |
15 |
Correct |
13 ms |
5716 KB |
Output is correct |
16 |
Correct |
5 ms |
5588 KB |
Output is correct |
17 |
Correct |
19 ms |
5616 KB |
Output is correct |
18 |
Correct |
19 ms |
5692 KB |
Output is correct |
19 |
Correct |
19 ms |
5588 KB |
Output is correct |
20 |
Correct |
15 ms |
5688 KB |
Output is correct |
21 |
Correct |
6 ms |
5588 KB |
Output is correct |
22 |
Execution timed out |
1092 ms |
125596 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |