Submission #1039855

#TimeUsernameProblemLanguageResultExecution timeMemory
1039855amirhoseinfar1385Comparing Plants (IOI20_plants)C++17
0 / 100
4048 ms100260 KiB
#include "plants.h" #include<bits/stdc++.h> using namespace std; const int maxn=5000+10; int all[maxn],tr[maxn],res[maxn][maxn],fake[maxn]; int k,n,vis[maxn],visa[maxn]; vector<int>adj[maxn]; void clear(){ for(int i=0;i<n;i++){ visa[i]=0; } } void isc(int u,int av){ visa[u]=1; res[av][u]=1; for(auto x:adj[u]){ if(visa[x]==0){ isc(x,av); } } } void init(int k_, std::vector<int> r) { k=k_; n=(int)r.size(); for(int i=0;i<n;i++){ all[i]=r[i]; } for(int i=0;i<n;i++){ fake[i]=all[i]; } for(int i=0;i<n;i++){ vector<int>tof; for(int j=0;j<n;j++){ if(fake[j]==0){ tof.push_back(j); } } vector<int>tofy; for(int j=(int)tof.size()-1;j>0;j--){ if(tof[j]-tof[j-1]>=k){ tofy.push_back(tof[j]); }else{ adj[tof[j-1]].push_back(tof[j]); } } if((tof[0]-tof.back()+n)%n>=k||(int)tof.size()==1){ tofy.push_back(tof[0]); } else{ adj[tof.back()].push_back(tof[0]); } for(int h=1;h<=k-1;h++){ fake[(tofy.back()-h+n)%n]--; if(vis[(tofy.back()-h+n)%n]==0){ adj[tofy.back()].push_back((tofy.back()-h+n)%n); } } vis[tofy.back()]=1; fake[tofy.back()]=-1; } for(int i=0;i<n;i++){ clear(); isc(i,i); } } int compare_plants(int x, int y) { if(res[x][y]){ return 1; } if(res[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...