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>
template <class T>
using Vec = std::vector<T>;
using Bit = std::bitset<500>;
int main() {
int R, C, M;
std::cin >> R >> C >> M;
Vec<Bit> grid_row(R);
for (int i = 0; i < R; ++i) {
for (int j = 0; j < C; ++j) {
char c;
std::cin >> c;
if (c == '.') {
grid_row[i].set(j);
}
}
}
auto row = grid_row;
while (M--) {
char c;
std::cin >> c;
if (c == 'N') {
for (int i = 0; i < R - 1; ++i) {
row[i] = row[i + 1] & grid_row[i];
}
row[R - 1] = Bit();
}
if (c == 'S') {
for (int i = R - 1; i > 0; --i) {
row[i] = row[i - 1] & grid_row[i];
}
row[0] = Bit();
}
if (c == 'E') {
for (int i = 0; i < R; ++i) {
row[i] = (row[i] << 1) & grid_row[i];
}
}
if (c == 'W') {
for (int i = 0; i < R; ++i) {
row[i] = (row[i] >> 1) & grid_row[i];
}
}
if (c == '?') {
Vec<Bit> nrow(R);
for (int i = 0; i < R; ++i) {
nrow[i] |= row[i] >> 1;
nrow[i] |= row[i] << 1;
if (i > 0) nrow[i] |= row[i - 1];
if (i + 1 < R) nrow[i] |= row[i + 1];
nrow[i] &= grid_row[i];
}
row = std::move(nrow);
}
}
int ans = 0;
for (int i = 0; i < R; ++i) {
ans += row[i].count();
}
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... |