Submission #613803

#TimeUsernameProblemLanguageResultExecution timeMemory
613803Koosha_mvComparing Plants (IOI20_plants)C++14
25 / 100
475 ms8688 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=5050,lg=20; int n,k,p[N],a[N],pos[N],vis[N][N]; pair<int,int> A[lg][N],B[lg][N]; void builda(){ int last=0; f_(T,n-1,0){ f(i,0,2*n){ if(p[i%n]==0){ if(i>=n && i-last>=k){ a[i-n]=T; f(j,0,k){ p[(i-j)%n]--; } break ; } last=i; } } } f(i,0,n) pos[a[i]]=i; //dbga(a,0,n); } void AB(){ set<int> s; f(i,0,k-1) s.insert(a[i]); f_(i,n-1,0){ int ida=-1,idb=-1; if(*s.begin()<a[i]){ ida=pos[*prev(s.lower_bound(a[i]))]; } if(*s.rbegin()>a[i]){ idb=pos[*s.lower_bound(a[i])]; } s.insert(a[i]); s.erase(a[(i+k-1)%n]); if(ida==-1){ A[0][i]={i,0}; } else{ A[0][i]={ida,(ida-i+n)%n}; } if(idb==-1){ B[0][i]={i,0}; } else{ B[0][i]={idb,(idb-i+n)%n}; } } f(l,1,lg){ f(i,0,n){ A[l][i]={A[l-1][A[l-1][i].F].F,A[l-1][i].S+A[l-1][A[l-1][i].F].S}; B[l][i]={B[l-1][B[l-1][i].F].F,B[l-1][i].S+B[l-1][B[l-1][i].F].S}; } } } bool checkA(int u,int v){ int len=(v-u+n)%n; f_(l,lg-1,0){ if(A[l][u].S<=len){ len-=A[l][u].S; u=A[l][u].F; } } if((v-u+n)%n<k && a[u]>=a[v]) return 1; return 0; } bool checkB(int u,int v){ int len=(v-u+n)%n; f_(l,lg-1,0){ if(B[l][u].S<=len){ //cout<<l<<" "<<u<<" -> "<<B[l][u].F<<" "<<B[l][u].S<<endl; len-=B[l][u].S; u=B[l][u].F; } } //eror(u); if((v-u+n)%n<k && a[u]<=a[v]) return 1; return 0; } void init(int _k,vector<int> _p) { n=_p.size(),k=_k; f(i,0,n) p[i]=_p[i]; builda(); AB(); //cout<<checkB(1,2)<<"!"<<endl; } int compare_plants(int x, int y) { if(checkA(x,y) || checkB(y,x)) return 1; if(checkB(x,y) || checkA(y,x)) return -1; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...