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>
#define int long long
using namespace std;
const int maxn = 500;
signed main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
//freopen("input.txt", "r", stdin);
// for writing output to output.txt
//freopen("output.txt", "w", stdout);
#endif
/*#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif*/ //fast IO
int n,m,k;
cin >> n >> m >> k;
bitset<maxn> B;
bitset<maxn> all0;
vector<bitset<maxn>> grid(n,B);
vector<bitset<maxn>> allowed(n,B);
for (int i=0; i<n; i++) {
string s;
cin >> s;
bitset<maxn> B1;
for (int j=0; j<m; j++) {
if (s[j]=='#') {
B1[j] = 0;
}
else {
B1[j] = 1;
}
}
grid[i] = allowed[i] = B1;
}
for (int let=0; let<k; let++) {
char c;
cin >> c;
//cout << let << " " << c << endl;
if (c=='N') {
for (int i=1; i<n; i++) {
allowed[i-1] = allowed[i];
}
allowed[n-1] = all0;
}
else if (c=='S') {
for (int i=n-2; i>=0; i--) {
//cout << "downing " << i << endl;
allowed[i+1] = allowed[i];
}
allowed[0] = all0;
}
else if (c=='W') {
for (int i=0; i<n; i++) {
allowed[i] >>= 1;
}
}
else if (c=='E') {
for (int i=0; i<n; i++) {
allowed[i] <<= 1;
}
}
else if (c=='?') {
//cout << "d" << let << endl;
vector<bitset<maxn>> allowed2(n,all0);
//cout << "e" << let << endl;
for (int i=0; i<n; i++) {
//cout << "doing " << i << endl;
allowed2[i] |= allowed[i]>>1;
allowed2[i] |= allowed[i]<<1;
}
for (int i=n-2; i>=0; i--) {
//cout << i << endl;
allowed2[i+1] |= allowed[i];
}
for (int i=1; i<n; i++) {
//cout << i << endl;
allowed2[i-1] |= allowed[i];
}
allowed=allowed2;
}
else {
assert(false);
}
for (int i=0; i<n; i++) {
allowed[i] &= grid[i];
}
}
int answer = 0;
for (int i=0; i<n; i++) {
answer+=allowed[i].count();
}
cout << answer << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |