#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;
#ifndef ONLINE_JUDGE
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
#else
#endif
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';
}
Compilation message
nautilus.cpp: In function 'int main()':
nautilus.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen("test.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen("test.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |