이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
#define ff first
#define ss second
#define pb push_back
const int oo = 1e9 + 7;
int r, c, m;
bitset<501> grid[502];
bitset<501> dp[502][5001];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> r >> c >> m;
for(int l = 1; l <= r; l++) {
for(int i = 1; i <= c; i++) {
char ch; cin >> ch;
if(ch == '.') grid[l][i] = 1;
dp[l][0][i] = grid[l][i];
}
}
string s; cin >> s;
for(int l = 1; l <= m; l++) {
for(int i = 1; i <= r; i++) {
if(s[l - 1] == 'S') dp[i][l] = dp[i - 1][l - 1] & grid[i];
if(s[l - 1] == 'N') dp[i][l] = dp[i + 1][l - 1] & grid[i];
if(s[l - 1] == 'E') dp[i][l] = (dp[i][l - 1] << 1) & grid[i];
if(s[l - 1] == 'W') dp[i][l] = (dp[i][l - 1] >> 1) & grid[i];
if(s[l - 1] == '?')
dp[i][l] = (dp[i + 1][l - 1] | dp[i - 1][l - 1] | (dp[i][l - 1] << 1) | (dp[i][l - 1] >> 1)) & grid[i];
}
}
int res = 0;
for(int l = 1; l <= r; l++) res += dp[l][m].count();
cout << res << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |