Submission #613789

#TimeUsernameProblemLanguageResultExecution timeMemory
613789Koosha_mvComparing Plants (IOI20_plants)C++14
0 / 100
1 ms852 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=505,lg=20; int n,k,p[N],a[N],vis[N][N]; pair<int,int> A[lg][N],B[lg][N]; struct tree{ int Time,st[N],ft[N],deg[N]; vector<int> g[N]; tree(){ Time=0; f(i,0,n) deg[i]=0; } bool ispar(int u,int v){ return st[u]<=st[v] && st[v]<ft[u]; } void add_edge(int u,int v){ g[u].pb(v); deg[v]++; } void dfs(int u){ st[u]=Time++; for(auto v : g[u]){ dfs(v); } ft[u]=Time; } void do_it(){ f(i,0,n){ if(deg[i]==0){ dfs(i); } } } } T1,T2; 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; } } } //dbga(a,0,n); } void AB(){ f(i,0,n){ int ida=-1,idb=-1; f(j,1,min(n-i,k)){ int x=(i+j)%n; if(a[x]<a[i] && (ida==-1 || a[x]>a[ida])){ ida=x; } if(a[x]>a[i] && (idb==-1 || a[x]<a[idb])){ idb=x; } } if(ida==-1){ A[0][i]={i,0}; } else{ A[0][i]={ida,ida-i}; } if(idb==-1){ B[0][i]={i,0}; } else{ B[0][i]={idb,idb-i}; } } 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){ len-=B[l][u].S; u=B[l][u].F; } } 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<<"ANS : "<<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...