이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bitset<505> dp[505][5005], sea[505];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
char mat[n][m];
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cin >> mat[i][j];
}
}
string str;
cin >> str;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
sea[i][j] = mat[i][j] == '.';
}
}
for(int i = 0; i < n; i++) {
dp[i][0] = sea[i];
}
for(int t = 0; t < k; t++) {
if (str[t] == 'N') {
for(int i = 0; i < n; i++) {
dp[i][t+1] = dp[i+1][t] & sea[i];
}
} else if (str[t] == 'S') {
for(int i = 1; i < n; i++) {
dp[i][t+1] = dp[i-1][t] & sea[i];
}
} else if (str[t] == 'E') {
for(int i = 0; i < n; i++) {
dp[i][t+1] = (dp[i][t] << 1) & sea[i];
}
} else if (str[t] == 'W') {
for(int i = 0; i < n; i++) {
dp[i][t+1] = (dp[i][t] >> 1) & sea[i];
}
} else if (str[t] == '?') {
for(int i = 0; i < n; i++) {
dp[i][t+1] = ((i+1 < n ? dp[i+1][t] : 0) |
(i-1 >= 0 ? dp[i-1][t] : 0) |
(dp[i][t] >> 1) |
(dp[i][t] << 1)) &
sea[i];
}
}
}
int ans = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
ans += dp[i][k][j];
}
}
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... |