This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 105, K = 105;
char g[N][N];
int dp[N][N][K];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, k;
std::cin >> n >> m >> k;
memset(g, '#', sizeof g);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
std::cin >> g[i][j];
}
}
std::string s;
std::cin >> s;
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j][0] = (g[i][j] == '.');
}
}
for (int K = 1; K <= k; K++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (g[i][j] == '#')
continue;
int x = i, y = j;
if (s[K - 1] == 'N') x++;
else if (s[K - 1] == 'S') x--;
else if (s[K - 1] == 'W') y++;
else if (s[K - 1] == 'E') y--;
else {
x--;
dp[i][j][K] |= dp[i - 1][j][K - 1];
dp[i][j][K] |= dp[i][j - 1][K - 1];
dp[i][j][K] |= dp[i + 1][j][K - 1];
dp[i][j][K] |= dp[i][j + 1][K - 1];
}
dp[i][j][K] |= dp[x][y][K - 1];
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
ans += dp[i][j][k];
}
}
std::cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |