This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
int R, C, M;
string s;
char c[501][501];
bitset<250000> org, cur, E, W;
int id(int i, int j) {
return i * C + j;
}
int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> R >> C >> M;
for (int i = 0; i < R; i++)
for (int j = 0; j < C; j++) {
cin >> c[i][j];
int pos = id(i, j);
if (c[i][j] == '.') {
org.set(pos);
cur.set(pos);
}
if (j != C - 1) W.set(pos);
if (j != 0) E.set(pos);
}
cin >> s;
for (int i = 0; i < M; i++) {
if (s[i] == 'N')
cur = (cur >> C);
else if (s[i] == 'S')
cur = (cur << C);
else if (s[i] == 'W')
cur = (cur >> 1) & W;
else if (s[i] == 'E')
cur = (cur << 1) & E;
else
cur = ((cur >> C) | (cur << C) | ((cur >> 1) & W) | ((cur << 1) & E));
cur &= org;
}
cout << cur.count();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |