이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int kN = 500;
bitset<kN> grid[1 + kN + 1];
bitset<kN> dp[2][1 + kN + 1];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, p;
cin >> n >> m >> p;
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
for (int j = 0; j < m; ++j) {
if (s[j] == '.') {
grid[i][j] = 1;
}
}
}
string moves;
cin >> moves;
for (int i = 1; i <= n; ++i) {
dp[0][i] = grid[i];
}
int t = 0;
for (int step = 0; step < p; ++step, t ^= 1) {
for (int i = 1; i <= n; ++i) {
dp[t ^ 1][i].reset();
if (moves[step] == 'N' || moves[step] == '?') {
dp[t ^ 1][i] |= dp[t][i + 1];
}
if (moves[step] == 'E' || moves[step] == '?') {
dp[t ^ 1][i] |= dp[t][i] << 1;
}
if (moves[step] == 'S' || moves[step] == '?') {
dp[t ^ 1][i] |= dp[t][i - 1];
}
if (moves[step] == 'W' || moves[step] == '?') {
dp[t ^ 1][i] |= dp[t][i] >> 1;
}
dp[t ^ 1][i] &= grid[i];
}
}
int res = 0;
for (int i = 1; i <= n; ++i) {
res += dp[t][i].count();
}
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... |