Submission #202327

#TimeUsernameProblemLanguageResultExecution timeMemory
202327errorgorn자리 배치 (IOI18_seats)C++14
25 / 100
1836 ms64960 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; struct node{ int seg[2005]; ///at least double the original array int padding=1005; void update(int i,int j){ i+=padding; seg[i]=j; i>>=1; while (i){ seg[i]=max(seg[i<<1],seg[(i<<1)|1]); i>>=1; } } int query(int l,int r){ //[l,r], with 0-indexing int res=0; for (l+=padding,r+=padding+1;l<r;l>>=1,r>>=1){ if (l&1){ res=max(res,seg[l]); l++; } if (r&1){ r--; res=max(res,seg[r]); } } return res; } }; int h,w; ii pos[1000005]; node hor[1005]; node ver[1005]; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { h=H,w=W; for (int x=0;x<h*w;x++){ pos[x]=ii(R[x],C[x]); ver[pos[x].first].update(pos[x].second,x); hor[pos[x].second].update(pos[x].first,x); } } int swap_seats(int a, int b) { swap(pos[a],pos[b]); ver[pos[a].first].update(pos[a].second,a); hor[pos[a].second].update(pos[a].first,a); ver[pos[b].first].update(pos[b].second,b); hor[pos[b].second].update(pos[b].first,b); int x1,x2,y1,y2; x1=x2=pos[0].first; y1=y2=pos[0].second; int s=1; int biggest=0; int res=1; while (s<h*w){ int best=1000000000,tmp; int dir=-1; if (0<x1){ tmp=ver[x1-1].query(y1,y2); if (tmp<best){ best=tmp; dir=0; } } if (x2<h-1){ tmp=ver[x2+1].query(y1,y2); if (tmp<best){ best=tmp; dir=1; } } if (0<y1){ tmp=hor[y1-1].query(x1,x2); if (tmp<best){ best=tmp; dir=2; } } if (y2<w-1){ tmp=hor[y2+1].query(x1,x2); if (tmp<best){ best=tmp; dir=3; } } if (dir==0){ x1--; s+=y2-y1+1; } else if (dir==1){ x2++; s+=y2-y1+1; } else if (dir==2){ y1--; s+=x2-x1+1; } else{ y2++; s+=x2-x1+1; } biggest=max(biggest,best); if (biggest==s-1) res++; } return res; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...