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>
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int r, c, m;
std::string s;
std::cin >> r >> c >> m;
std::vector<std::vector<char>> a(r + 1, std::vector<char>(c + 1));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
std::cin >> a[i][j];
}
}
std::cin >> s;
s = "#" + s;
std::vector<std::vector<int>> can(r + 1, std::vector<int>(c + 1));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if (a[i][j] == '.') {
can[i][j] = 1;
}
}
}
for (int it = 1; it <= m; it++) {
std::vector<std::vector<int>> aux(r + 1, std::vector<int>(c + 1, 0));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if (a[i][j] == '#') {
continue;
}
if (s[it] == '?') {
for (int d = 0; d < 4; ++d) {
int x = i + dx[d];
int y = j + dy[d];
if (1 <= x && x <= r && 1 <= y && y <= c && can[x][y] == 1) {
aux[i][j] = 1;
}
}
continue;
}
if (s[it] == 'W' && j + 1 <= c && can[i][j + 1] == 1) {
aux[i][j] = 1;
}
if (s[it] == 'E' && j - 1 >= 1 && can[i][j - 1] == 1) {
aux[i][j] = 1;
}
if (s[it] == 'N' && i + 1 <= r && can[i + 1][j] == 1) {
aux[i][j] = 1;
}
if (s[it] == 'S' && i - 1 >= 1 && can[i - 1][j] == 1) {
aux[i][j] = 1;
}
}
}
swap(can, aux);
}
int res = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if (can[i][j] == 1) {
res++;
}
}
}
std::cout << res << "\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |