Submission #491844

#TimeUsernameProblemLanguageResultExecution timeMemory
491844codr0Nautilus (BOI19_nautilus)C++14
100 / 100
185 ms844 KiB
// Code by Parsa Eslami #include <bits/stdc++.h> #define int long long #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORR(i,a,b) for(int i=a;i>=b;i--) #define S second #define F first #define pb push_back #define SZ(x) (int)x.size() #define all(x) x.begin(),x.end() #define err(x) cerr<<#x<<" : "<<x<<'\n' #define MOD(x) if(x>=M) x-=M; if(x<0) x+=M; using namespace std; const int N=500+3; bitset<N> ocean[N]; bitset<N> B1[N]; bitset<N> BW[N]; bitset<N> BE[N]; bitset<N> BN[N]; bitset<N> BS[N]; int r,c; void Do(int x0,int y0){ if(x0==0){ if(y0==1){ FOR(i,1,r) BE[i]=B1[i]<<1; }else{ FOR(i,1,r) BW[i]=B1[i]>>1; } }else{ if(x0==1){ BS[1].reset(); FOR(i,2,r) BS[i]=B1[i-1]; }else{ FOR(i,1,r-1) BN[i]=B1[i+1]; BN[r].reset(); } } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int m; cin>>r>>c>>m; FOR(i,1,r){ FOR(j,1,c) { char x0; cin>>x0; if(x0!='#') ocean[i][j]=1; } } string S; cin>>S; FOR(i,1,r) FOR(j,1,c) B1[i][j]=ocean[i][j]; FOR(i,0,m-1){ if(S[i]=='?'){ Do(1,0); Do(0,1); Do(-1,0); Do(0,-1); FOR(i0,1,r) B1[i0]=((BS[i0]|BW[i0]|BE[i0]|BN[i0])&ocean[i0]); }else if(S[i]=='W') { Do(0,-1); FOR(i0,1,r) B1[i0]=((BW[i0])&ocean[i0]); } else if(S[i]=='E'){ Do(0,+1); FOR(i0,1,r) B1[i0]=((BE[i0])&ocean[i0]); } else if(S[i]=='N'){ Do(-1,0); FOR(i0,1,r) B1[i0]=((BN[i0])&ocean[i0]); } else if(S[i]=='S'){ Do(+1,0); FOR(i0,1,r) B1[i0]=((BS[i0])&ocean[i0]); } } int ans=0; FOR(i,1,r) FOR(j,1,c) ans+=B1[i][j]; cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...