이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |