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 ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 5e5 + 1;
bitset <512> cur[505];
bitset <512> valid[505];
int main(){
int n, m, q; cin >> n >> m >> q;
char c[n + 1][m + 1];
for(int i = 1 ;i <= n; i++){
for(int j = 1 ;j <= m; j++)
cin >> c[i][j];
for(int j = 1 ;j <= m; j++){
if(c[i][j] == '.')
valid[i][j] = 1, cur[i][j] = 1;
}
}
for(int i = 1; i <= q; i++){
char c; cin >> c;
if(c == 'W'){
for(int j = 1; j <= n; j++)
cur[j] >>= 1,cur[j] &= valid[j];
}
if(c == 'E'){
for(int j = 1; j <= n; j++)
cur[j] <<= 1, cur[j] &= valid[j];
}
if(c == 'N'){
for(int j = 1; j <= n; j++){
cur[j] = cur[j + 1] & valid[j];
}
}
if(c == 'S'){
for(int j = n; j >= 1; j--)
cur[j] = cur[j - 1] & valid[j];
}
if(c == '?'){
bitset <512> x, y;
bitset <512> pr;
for(int j = 1; j <= n; j++){
x = (cur[j] >> 1);
y = (cur[j] << 1);
x |= y;
x |= pr;
x |= cur[j + 1];
pr = cur[j];
x &= valid[j];
cur[j] = x;
}
}
}
int ans = 0;
for(int j = 0; j <= n; j++)
for(int i = 1 ;i <= m; i++)
if(cur[j][i]) ans++;
cout << ans;
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... |