이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define arr array
#define vct vector
const int MX_R = 5e2 + 5, MX_C = 5e2 + 5, MX_N = 5e3 + 5;
int r, c, n;
bool wll[MX_R][MX_C];
arr<char, MX_N> mv;
bitset<MX_C> ps[2][MX_R];
vct<pii> nt_wll;
void cmp() {
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
if (!wll[i][j]) nt_wll.push_back({i, j});
for (pii& x : nt_wll) ps[0][x.first][x.second] = true;
for (int i = 1; i <= n; i++) {
int prty = i % 2, opp_prty = (i + 1) % 2;
if (mv[i] == 'W') {
for (pii& x : nt_wll)
ps[prty][x.first][x.second] = ps[opp_prty][x.first][x.second + 1];
}
if (mv[i] == 'E') {
for (pii& x : nt_wll)
ps[prty][x.first][x.second] = ps[opp_prty][x.first][x.second - 1];
}
if (mv[i] == 'S') {
for (pii& x : nt_wll)
ps[prty][x.first][x.second] = ps[opp_prty][x.first - 1][x.second];
}
if (mv[i] == 'N') {
for (pii& x : nt_wll)
ps[prty][x.first][x.second] = ps[opp_prty][x.first + 1][x.second];
}
if (mv[i] == '?') {
for (pii& x : nt_wll)
ps[prty][x.first][x.second] = ps[opp_prty][x.first][x.second + 1] | ps[opp_prty][x.first][x.second - 1]
| ps[opp_prty][x.first - 1][x.second] | ps[opp_prty][x.first + 1][x.second];
}
// cout << mv[i] << ": " << "----------------" << endl;
// for (int j = 1; j <= r; j++) {
// for (int k = 1; k <= c; k++) cout << ps[prty][j][k];
// cout << endl;
// }
}
}
int main() {
// freopen("nt.in", "r", stdin);
cin.sync_with_stdio(false), cin.tie(0);
cin >> r >> c >> n;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
char x; cin >> x;
wll[i][j] = (x == '#');
}
}
for (int i = 1; i <= n; i++) cin >> mv[i];
cmp();
int ans = 0;
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++) ans += ps[n % 2][i][j];
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |