Submission #388255

#TimeUsernameProblemLanguageResultExecution timeMemory
388255alexxela12345Comparing Plants (IOI20_plants)C++17
14 / 100
4064 ms9788 KiB
#include <bits/stdc++.h> #include "plants.h" using namespace std; int n; int k; vector<int> r; void genSome(); void init(int k_, std::vector<int> r_) { k = k_; r = r_; n = r.size(); genSome(); } vector<int> h; int cur; vector<int> tree; void build() { tree = r; } pair<int, int> GetMin(int l, int r) { // l might be negative pair<int, int> ans = {n, -1}; for (int i = l; i < r; i++) { ans = min(ans, {tree[(i + n) % n], (i + n) % n}); } return ans; } void Set(int ind, int x) { tree[ind] = x; } void Add(int l, int r, int x) { for (int i = l; i < r; i++) { int j = (i + n) % n; tree[j] += x; } } void rec(int ind) { while (true) { auto pp = GetMin(ind - k + 1, ind); if (pp.first == 0) { rec(pp.second); } else { break; } } h[ind] = cur--; Set(ind, n); Add(ind - k + 1, ind, -1); } void genSome() { h.resize(n, -1); build(); cur = n; while (true) { auto pp = GetMin(0, n); if (pp.first == 0) { rec(pp.second); } else { break; } } } int compare_plants(int x, int y) { if (h[x] > h[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...