#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define pllll pair<pll,pll>
#define vl vector<ll>
#define vll vector<pll>
#define vlll vector<plll>
#define vllll vector<pllll>
#define vb vector<bool>
#define sz size()
#define fr front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bk back();
using namespace std;
const ld pi=3.14159265359;
const ll e5=1e5;
const ll e6=1e6;
const ll e9=1e9;
const ll inf=1e18;
const ll mod=1e9+7;
const ll mod2=998244353;
const ll N=1e5+5;
ll bpm(ll x,ll y,ll m){if(y==0)return 1%m;if(y==1)return x%m;ll p=bpm(x,y/2,m);
if(y%2==0)return p*p%m;else return p*p%m*x%m;}
ll bp(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll p=bp(x,y/2);
if(y%2==0)return p*p;else return p*p*x;}
void solve(/**/){
ll r,c,m;
string s;
cin>>r>>c>>m;
vector<bitset<500> > a(r),b(r),down(r),up(r),left(r),right(r);
bitset<500> zr;
for(ll i=0;i<r;i++){
for(ll j=0;j<c;j++){
char ch; cin>>ch;
if(ch=='.'){
a[i][j]=b[i][j]=(ch=='.');
}
}
}
cin>>s;
for(char ch:s){
if(ch=='N'){
for(ll i=0;i<r-1;i++){
a[i]=a[i+1];
}
a[r-1]=zr;
}else if(ch=='E'){
for(ll i=0;i<r;i++){
a[i]<<=1;
}
}else if(ch=='S'){
for(ll i=r-1;i>0;i--){
a[i]=a[i-1];
}
a[0]=zr;
}else if(ch=='W'){
for(ll i=0;i<r;i++){
a[i]>>=1;
}
}else if(ch=='?'){
up[0]=zr;
down[r-1]=zr;
for(ll i=0;i<r;i++){
if(i!=0) up[i]=a[i-1];
if (i!=r-1) down[i]=a[i+1];
left[i]=(a[i]>>1);
right[i]=(a[i]<<1);
}
for(ll i=0;i<r;i++){
a[i]=up[i]|down[i]|right[i]|left[i];
a[i]&=b[i];
}
}
for(ll i=0;i<r;i++) a[i]&=b[i];
}
ll x=0;
for(ll i=0;i<r;i++){
for(ll j=0;j<c;j++){
if(a[i][j]) x++;
}
}
cout<<x;
return;
}
int main(/*Aldk*/){
ios_base::sync_with_stdio(false);cin.tie(NULL);
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
//cout<<setprecision(6)<<fixed;
ll T=1;
//cin>>T;
for(ll i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
//cout<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
66 ms |
888 KB |
Output is correct |
23 |
Correct |
57 ms |
604 KB |
Output is correct |
24 |
Correct |
55 ms |
604 KB |
Output is correct |
25 |
Correct |
54 ms |
604 KB |
Output is correct |
26 |
Correct |
52 ms |
600 KB |
Output is correct |
27 |
Correct |
98 ms |
624 KB |
Output is correct |
28 |
Correct |
100 ms |
600 KB |
Output is correct |
29 |
Correct |
101 ms |
624 KB |
Output is correct |
30 |
Correct |
101 ms |
632 KB |
Output is correct |
31 |
Correct |
101 ms |
604 KB |
Output is correct |
32 |
Correct |
132 ms |
600 KB |
Output is correct |
33 |
Correct |
134 ms |
624 KB |
Output is correct |
34 |
Correct |
137 ms |
604 KB |
Output is correct |
35 |
Correct |
138 ms |
628 KB |
Output is correct |
36 |
Correct |
135 ms |
600 KB |
Output is correct |