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;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
using ll = long long;
const int mod = 1e9+7;
void solve(int tc) {
int r, c, m;
cin >> r >> c >> m;
const int mxRC = 500 * 500;
bitset<mxRC> cur, can;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
char x;
cin >> x;
can[i*c+j] = cur[i*c+j] = (x == '.');
}
}
bitset<mxRC> lastcol, firstcol;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
firstcol[i*c+j] = j != 0;
lastcol[i*c+j] = j != c-1;
}
}
string s;
cin >> s;
for (char x : s) {
bitset<mxRC> prev = cur;
cur = 0;
if (x == 'S' or x == '?') cur |= (prev << c) & can;
if (x == 'N' or x == '?') cur |= (prev >> c) & can;
if (x == 'E' or x == '?') cur |= (prev << 1) & can & firstcol;
if (x == 'W' or x == '?') cur |= (prev >> 1) & can & lastcol;
}
cout << cur.count() << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
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... |