#include <bits/stdc++.h>
using namespace std;
const int MAX = 105;
int R, C, M;
char grid[MAX][MAX];
string dir;
int dx[4] = {-1, 0, 1, 0}; // N, E, S, W
int dy[4] = {0, 1, 0, -1};
char dc[4] = {'N', 'E', 'S', 'W'};
bool inGrid(int x, int y) {
return x >= 0 && x < R && y >= 0 && y < C && grid[x][y] == '.';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> R >> C >> M;
for (int i = 0; i < R; ++i)
cin >> grid[i];
cin >> dir;
set<pair<int, int>> curr;
// Khởi tạo: tất cả ô nước là vị trí ban đầu có thể
for (int i = 0; i < R; ++i)
for (int j = 0; j < C; ++j)
if (grid[i][j] == '.')
curr.insert({i, j});
// Lặp qua từng bước trong chuỗi tín hiệu
for (int step = 0; step < M; ++step) {
set<pair<int, int>> next;
for (auto [x, y] : curr) {
if (dir[step] == '?') {
for (int d = 0; d < 4; ++d) {
int nx = x + dx[d];
int ny = y + dy[d];
if (inGrid(nx, ny)) {
next.insert({nx, ny});
}
}
} else {
int d = find(dc, dc + 4, dir[step]) - dc;
int nx = x + dx[d];
int ny = y + dy[d];
if (inGrid(nx, ny)) {
next.insert({nx, ny});
}
}
}
curr = next; // Cập nhật tập trạng thái
}
cout << curr.size() << '\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... |