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"
using namespace std;
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
using ll = long long;
bitset<505> dp[505][5005], water[505];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
int r, c, m; cin >> r >> c >> m;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
char cur; cin >> cur;
if (cur == '.') {
water[i].set(j, 1);
dp[i][0].set(j, 1);
}
}
}
string command; cin >> command;
for (int i = 1; i <= m; i++) {
for (int row = 1; row <= r; row++) {
switch (command[i -1]) {
case 'N':
dp[row][i] = dp[row + 1][i-1] & water[row];
break;
case 'E':
dp[row][i] = (dp[row][i-1] << 1) & water[row];
break;
case 'S':
dp[row][i] = dp[row - 1][i-1] & water[row];
break;
case 'W':
dp[row][i] = (dp[row][i-1] >> 1) & water[row];
break;
case '?':
dp[row][i] = (dp[row + 1][i - 1] | (dp[row][i - 1] << 1) | dp[row - 1][i - 1] | (dp[row][i - 1] >> 1)) & water[row];
break;
}
}
}
int ans = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if (dp[i][m].test(j)) ans++;
}
}
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... |