Submission #1239012

#TimeUsernameProblemLanguageResultExecution timeMemory
1239012SalihSahinComparing Plants (IOI20_plants)C++20
0 / 100
4094 ms2632 KiB
#include "bits/stdc++.h" #include "plants.h" #define pb push_back using namespace std; vector<int> mnsg, mxsg; void init(int k, vector<int> r) { int n = r.size(); for(int i = 0; i < n; i++){ r[i] = (k - 1) - r[i]; } vector<int> mns(n, n-1); for(int cur = 0; cur < n; cur++){ vector<int> now = r, candnow(n), act(n, 1); set<int> cand; bool cand_cur = 0; for(int i = 0; i < n; i++){ if(!now[i]){ cand.insert(i); candnow[i] = true; } } // candidate olana kadar sagımda alabilecegim ilk elemanı al upd at onu deaktive et // eger ben candidate isem solda alabilecegim ilk elemanı al upd at onu deaktive et öyle ki solum boşalana ve kendimi alana kadar int cnt = 0; while(true){ int opbas = 0; if(candnow[cur] == false){ if(!cand.size()){ cout<<cur<<" ve "<<cnt<<" bakarken patladık "<<endl; abort(); } auto nxt = cand.lower_bound(cur); if(nxt == cand.end()){ nxt = cand.begin(); } opbas = *nxt; } else{ int lst = cur; for(int j = cur-1; j > cur-n; j--){ if(candnow[(j + n)%n] && lst - j < k){ lst = j; } } opbas = (lst + n)%n; } if(opbas == cur) break; cnt++; cand.erase(cand.find(opbas)); candnow[opbas] = 0; act[opbas] = 0; for(int i = opbas-1; i > opbas-k; i--){ if(!act[(i+n)%n]) continue; if(candnow[(i+n)%n]) continue; now[(i + n)%n]--; if(!now[(i + n)%n]){ cand.insert((i + n)%n); candnow[(i + n)%n] = 1; } } } mns[cur] = cnt; } mnsg = mns; for(int i = 0; i < n; i++){ r[i] = (k - 1) - r[i]; } vector<int> mxs(n, n-1); for(int cur = 0; cur < n; cur++){ vector<int> now = r, candnow(n), act(n, 1); set<int> cand; bool cand_cur = 0; for(int i = 0; i < n; i++){ if(!now[i]){ cand.insert(i); candnow[i] = true; } } // candidate olana kadar sagımda alabilecegim ilk elemanı al upd at onu deaktive et // eger ben candidate isem solda alabilecegim ilk elemanı al upd at onu deaktive et öyle ki solum boşalana ve kendimi alana kadar int cnt = 0; while(true){ int opbas = 0; if(candnow[cur] == false){ if(!cand.size()){ cout<<cur<<" ve "<<cnt<<" bakarken patladık "<<endl; abort(); } auto nxt = cand.lower_bound(cur); if(nxt == cand.end()){ nxt = cand.begin(); } opbas = *nxt; } else{ int lst = cur; for(int j = cur-1; j > cur-n; j--){ if(candnow[(j + n)%n] && lst - j < k){ lst = j; } } opbas = (lst + n)%n; } if(opbas == cur) break; cnt++; cand.erase(cand.find(opbas)); candnow[opbas] = 0; act[opbas] = 0; for(int i = opbas-1; i > opbas-k; i--){ if(!act[(i+n)%n]) continue; if(candnow[(i+n)%n]) continue; now[(i + n)%n]--; if(!now[(i + n)%n]){ cand.insert((i + n)%n); candnow[(i + n)%n] = 1; } } } mxs[cur] = cnt; } mxsg = mxs; for(int i = 0; i < n; i++){ mxsg[i] = n - mxsg[i] - 1; //cout<<i<<" : "<<mnsg[i]<<" "<<mxsg[i]<<endl; } return; } int intersect(pair<int, int> p1, pair<int, int> p2){ if(p1.first > p2.second || p2.first > p1.second) return 0; else return 1; } int compare_plants(int x, int y){ if(intersect({mnsg[x], mxsg[x]}, {mnsg[y], mxsg[y]})) return 0; if(mnsg[x] > mnsg[y]) return 1; else return -1; }
#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...