#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 1<<9, maxk = 101, lg = 21, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
deque<bitset<maxn>> dq, tmp, e;
bitset<maxn> bs[maxn], ex;
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n, m, l; cin >> n >> m >> l;
rep(i,0,n) rep(j,0,m){
char c; cin >> c;
bs[i][j] = c == '.';
}
rep(i,0,n) dq.pb(bs[i]), tmp.pb(ex);
auto top = [&](){
dq.pop_back();
dq.push_front(ex);
rep(i,0,n) dq[i] &= bs[i];
};
auto right = [&](){
rep(i,0,n) dq[i] = (dq[i]>>1)&bs[i];
};
auto down = [&](){
dq.pop_front();
dq.pb(ex);
rep(i,0,n) dq[i] &= bs[i];
};
auto left = [&](){
rep(i,0,n) dq[i] = (dq[i]<<1)&bs[i];
};
while(l--){
char c; cin >> c;
if(c == 'N') down();
if(c == 'E') left();
if(c == 'S') top();
if(c == 'W') right();
if(c == '?') {
rep(i,0,n) tmp[i].reset();
e = dq;
top();
rep(i,0,n) tmp[i] |= dq[i];
dq = e;
right();
rep(i,0,n) tmp[i] |= dq[i];
dq = e;
down();
rep(i,0,n) tmp[i] |= dq[i];
dq = e;
left();
rep(i,0,n) tmp[i] |= dq[i];
dq = tmp;
}
}
int ans = 0;
rep(i,0,n) rep(j,0,m) ans += dq[i][j];
cout << ans << '\n';
return 0;
}
# |
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 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
109 ms |
448 KB |
Output is correct |
23 |
Correct |
108 ms |
444 KB |
Output is correct |
24 |
Correct |
109 ms |
340 KB |
Output is correct |
25 |
Correct |
106 ms |
448 KB |
Output is correct |
26 |
Correct |
115 ms |
448 KB |
Output is correct |
27 |
Correct |
190 ms |
468 KB |
Output is correct |
28 |
Correct |
197 ms |
356 KB |
Output is correct |
29 |
Correct |
202 ms |
340 KB |
Output is correct |
30 |
Correct |
202 ms |
448 KB |
Output is correct |
31 |
Correct |
202 ms |
468 KB |
Output is correct |
32 |
Correct |
261 ms |
468 KB |
Output is correct |
33 |
Correct |
264 ms |
448 KB |
Output is correct |
34 |
Correct |
266 ms |
340 KB |
Output is correct |
35 |
Correct |
267 ms |
340 KB |
Output is correct |
36 |
Correct |
259 ms |
448 KB |
Output is correct |