이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 505;
int n, m, k;
char c[N][N];
bitset<N> init[N];
bitset<N> dp[N][2];
string s;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c[i][j];
if (c[i][j] == '.') init[i].set(j);
}
dp[i][1] = init[i];
}
cin >> s;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
dp[j][0] = dp[j][1];
dp[j][1].reset();
}
for (int j = 1; j <= n; j++) {
if (s[i - 1] == 'W') dp[j][1] |= (dp[j][0] >> 1);
if (s[i - 1] == 'E') dp[j][1] |= (dp[j][0] << 1);
if (s[i - 1] == 'N') dp[j][1] |= dp[j + 1][0];
if (s[i - 1] == 'S') dp[j][1] |= dp[j - 1][0];
if (s[i - 1] == '?') {
dp[j][1] |= (dp[j][0] >> 1);
dp[j][1] |= (dp[j][0] << 1);
dp[j][1] |= dp[j + 1][0];
dp[j][1] |= dp[j - 1][0];
}
dp[j][1] &= init[j];
}
}
int ans = 0;
for (int i = 1; i <= n; i++) ans += dp[i][1].count();
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |