Submission #401060

#TimeUsernameProblemLanguageResultExecution timeMemory
401060A_DLand of the Rainbow Gold (APIO17_rainbow)C++14
11 / 100
3075 ms5708 KiB
//#include "rainbow.h" #include <bits/stdc++.h> /* static int R, C, M, Q; static int sr, sc; static char S[100000 + 5]; */ #define LL long long using namespace std; const int N=51; bool a[N][N]; bool vis[N][N]; int mnr,mnc,mxr,mxc; int x[]={0,0,1,-1}; int y[]={1,-1,0,0}; bool ok(int i,int j) { return vis[i][j]==0&&a[i][j]==0&&mnr<=i&&i<=mxr&&mnc<=j&&j<=mxc; } void dfs(int i,int j) { vis[i][j]=1; for(int k=0;k<4;k++){ int ni=i+x[k]; int nj=j+y[k]; if(ok(ni,nj)){ dfs(ni,nj); } } } void init(int R, int C, int sr, int sc, int M, char *S) { // cout<<5<<endl; string s; s+=S; /* for(int i=1;i<=M;i++){ cout<<s<<endl; S++; } cout<<s<<endl; */ int x=sr; int y=sc; a[x][y]=1; for(auto z:s){ if(z=='N'){ x--; } if(z=='S'){ x++; } if(z=='W'){ y--; } if(z=='E'){ y++; } a[x][y]=1; } /* for(int i=1;i<=R;i++){ for(int j=1;j<=C;j++){ cout<<a[i][j]<<" "; } cout<<endl; } */ } int colour(int ar, int ac, int br, int bc) { memset(vis,0,sizeof(vis)); mnr=ar; mnc=ac; mxr=br; mxc=bc; int ans=0; for(int i=mnr;i<=mxr;i++){ for(int j=mnc;j<=mxc;j++){ if(a[i][j]==0&&vis[i][j]==0){ ans++; dfs(i,j); } } } return ans; } /* int main() { scanf("%d %d %d %d", &R, &C, &M, &Q); scanf("%d %d", &sr, &sc); if (M > 0) { scanf(" %s ", S); } init(R, C, sr, sc, M, S); int query; for (query = 0; query < Q; query++) { int ar, ac, br, bc; scanf("%d %d %d %d", &ar, &ac, &br, &bc); printf("%d\n", colour(ar, ac, br, bc)); } return 0; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...