using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int rows, cols, m;
string commands;
const int maxrows = 501;
vector<bitset<maxrows>> blocked(maxrows);
vector<bitset<maxrows>> yes(maxrows), nyes(maxrows);
int main() {
cin >> rows >> cols >> m;
blocked.resize(rows);
rep(r,0,rows) blocked[r].reset();
rep(r,0,rows) {
string s; cin >> s;
rep(c,0,cols) {
if (s[c] == '.') blocked[r].set(c);
}
}
cin >> commands;
rep(r,0,rows) yes[r].set();
rep(i,0,m) {
rep(r,0,rows) nyes[r].reset();
if (commands[i] == 'W') {
rep(r,0,rows) nyes[r] = (yes[r] >> 1) & blocked[r];
}
if (commands[i] == 'E') {
rep(r,0,rows) nyes[r] = (yes[r] << 1) & blocked[r];
}
if (commands[i] == 'S') {
if (rows == 1) {cout << 0 << endl; exit(0);}
rep(r,0,rows - 1) nyes[r] = yes[r + 1] & blocked[r];
}
if (commands[i] == 'N') {
if (rows == 1) {cout << 0 << endl; exit(0);}
rep(r,1,rows) nyes[r] = yes[r - 1] & blocked[r];
}
if (commands[i] == '?') {
if (rows == 1 && cols == 1) {
cout << 0 << endl;
exit(0);
}
else if (rows == 1) {
nyes[0] = ((yes[0] >> 1) | (yes[0] << 1)) & blocked[0];
} else {
nyes[0] = (yes[1] | (yes[0] >> 1) | (yes[0] << 1)) & blocked[0];
rep(r,1,rows - 1) {
nyes[r] = (yes[r + 1] | yes[r - 1] | (yes[r] >> 1) | (yes[r] << 1)) & blocked[r];
}
nyes[rows - 1] = (yes[rows - 2] | (yes[rows - 1] >> 1) | (yes[rows - 1] << 1)) & blocked[rows - 1];
}
}
rep(r,0,rows) yes[r] = nyes[r];
}
int ans = 0;
rep(r,0,rows) rep(c,0,cols) if (yes[r].test(c)) ans++;
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |