This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |