#include <bits/stdc++.h>
using namespace std;
#define oo 1e18
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) (((xxxx)>>(aaaa-1))&1)
#define fi first
#define se second
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<pair<int,int>,pair<int,int>> piiii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;
typedef pair<long double,long double> pld;
typedef pair<pair<long double,long double>,long double> plld;
typedef pair<long double,long long> pdl;
//const ll base=2e9+4257;
const int mod=1e9+7;
const ll mod2=1e9+4233;
const ld eps=1e-7;
const ld eps2=1e-7;
const int maxn=4e5+8;
const ll maxa=1e14;
const ld pi=acos(-1);
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
bitset<509> west[509],north[509],east[509],south[509],ans[509],basebitset[509],emptybitset;
int n,res,m,k,i,j;
char a[509][509];
string s;
void updatewest() {
for (int ii=1;ii<=n;ii++) {
west[ii]=(ans[ii]>>1);
}
}
void updateeast() {
for (int ii=1;ii<=n;ii++) {
east[ii]=(ans[ii]<<1);
}
}
void updatenorth() {
for (int ii=1;ii<n;ii++) {
north[ii]=ans[ii+1];
}
north[n]|=emptybitset;
}
void updatesouth() {
for (int ii=1;ii<n;ii++) {
south[ii+1]=ans[ii];
}
south[1]|=emptybitset;
}
int main(){
IO;
cin>>n>>m>>k;
for (i=1;i<=n;i++) {
for (j=1;j<=m;j++) {
cin>>a[i][j];
if (a[i][j]=='#') {
}
else {
basebitset[i][j]=true;
}
}
}
cin>>s;
s=" "+s;
for (i=1;i<=n;i++) {
for (j=1;j<=m;j++) {
ans[i][j]=true;
}
}
for (i=1;i<=n;i++) {
ans[i]&=basebitset[i];
}
//return 0;
for (j=1;j<=k;j++) {
if (s[j]=='W') {
updatewest();
for (i=1;i<=n;i++) {
ans[i]=west[i];
}
}
else if (s[j]=='E') {
updateeast();
for (i=1;i<=n;i++) {
ans[i]=east[i];
}
}
else if (s[j]=='S') {
updatesouth();
for (i=1;i<=n;i++) {
ans[i]=south[i];
}
}
else if (s[j]=='N') {
updatenorth();
for (i=1;i<=n;i++) {
ans[i]=north[i];
}
}
else if (s[j]=='?') {
updatewest();
updateeast();
updatenorth();
updatesouth();
for (i=1;i<=n;i++) {
ans[i]=west[i];
}
for (i=1;i<=n;i++) {
ans[i]|=east[i];
}
for (i=1;i<=n;i++) {
ans[i]|=south[i];
}
for (i=1;i<=n;i++) {
ans[i]|=north[i];
}
}
for (i=1;i<=n;i++) {
ans[i]&=basebitset[i];
}
/*
for (int ii=1;ii<=n;ii++) {
for (int ij=1;ij<=m;ij++) {
if (ans[ii][ij]) {
cout<<'.';
}
else {
cout<<'#';
}
}
cout<<'\n';
}
cout<<'\n';
*/
}
for (i=1;i<=n;i++) {
res+=ans[i].count();
}
cout<<res<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
64 ms |
1100 KB |
Output is correct |
23 |
Correct |
54 ms |
1008 KB |
Output is correct |
24 |
Correct |
50 ms |
1012 KB |
Output is correct |
25 |
Correct |
60 ms |
1012 KB |
Output is correct |
26 |
Correct |
48 ms |
988 KB |
Output is correct |
27 |
Correct |
77 ms |
924 KB |
Output is correct |
28 |
Correct |
80 ms |
972 KB |
Output is correct |
29 |
Correct |
87 ms |
1004 KB |
Output is correct |
30 |
Correct |
87 ms |
1068 KB |
Output is correct |
31 |
Correct |
74 ms |
988 KB |
Output is correct |
32 |
Correct |
94 ms |
972 KB |
Output is correct |
33 |
Correct |
94 ms |
964 KB |
Output is correct |
34 |
Correct |
93 ms |
972 KB |
Output is correct |
35 |
Correct |
97 ms |
1008 KB |
Output is correct |
36 |
Correct |
98 ms |
972 KB |
Output is correct |