#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
int n, k;
vector<int> r, vals;
bool check(int pos) {
pos = (pos - 1 + n) % n;
for (int i = 0; i < k; i++) {
if (r[pos] == 0) return 0;
pos = (pos - 1 + n) % n;
}
return 1;
}
void upd(int pos, int val) {
r[pos]--;
pos = (pos - 1 + n) % n;
for (int i = 0; i < k; i++) {
if (r[pos] == 0) vals[pos] = val;
r[pos]--;
pos = (pos - 1) % n;
}
}
void init(int _k, vector<int> _r) {
r = _r;
n = r.size();
k = _k;
k--;
vals.resize(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (r[j] == 0) {
if (check(j)) {
upd(j, 2 * (n - i) - 1);
vals[j] = 2 * (n - i);
break;
}
}
}
}
}
int compare_plants(int x, int y) {
if (vals[x] == vals[y]) return 0;
return (vals[x] > vals[y] ? 1 : -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... |