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;
using ll = long long;
using ld = long double;
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
template<class T> bool remin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool remax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
const int N = 502;
const int M = 5002;
bitset<N> a[N];
bitset<N> dp[N][M];
signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);
int n, m, k, i, j;
cin >> n >> m >> k;
for(i = 1; i <= n; i++) for(j = 1; j <= m; j++) {
char c; cin >> c;
if(c == '.') dp[i][0][j] = a[i][j] = true;
}
string s;
cin >> s;
for(int x = 0; x < k; x++) {
if(s[x] == 'N') {
for(i = 1; i < n; i++) dp[i][x + 1] |= (dp[i + 1][x] & a[i]);
}
else if(s[x] == 'S') {
for(i = 2; i <= n; i++) dp[i][x + 1] |= (dp[i - 1][x] & a[i]);
}
else if(s[x] == 'E') {
for(i = 1; i <= n; i++) dp[i][x + 1] |= ((dp[i][x] << 1) & a[i]);
}
else if(s[x] == 'W') {
for(i = 1; i <= n; i++) dp[i][x + 1] |= ((dp[i][x] >> 1) & a[i]);
}
else {
for(i = 1; i <= n; i++) dp[i][x + 1] |= (((dp[i][x] >> 1) | (dp[i][x] << 1) | dp[i + 1][x] | dp[i - 1][x]) & a[i]);
}
}
int ans = 0;
for(i = 1; i <= n; i++) for(j = 1; 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... |