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 "plants.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, K;
vector<int> R, A;
int dis(int x, int y) {
if (x < y) {
return y - x;
} else {
return N - y + x;
}
}
void init(int k, std::vector<int> r) {
K = k, R = r; N = R.size();
A.resize(N, -1);
for (int i = 0; i < N; i++) {
vector<int> v;
for (int j = 0; j < N; j++) {
if (A[j] == -1 && R[j] == K - 1) {
v.push_back(j);
}
}
int m = v.size(), p;
vector<int> c;
if (m == 1) {
c = {v[0]};
} else {
for (int j = 0; j + 1 < m; j++) {
assert(dis(v[j], v[(j + 1) % m]) == v[j + 1] - v[j]);
if (v[j + 1] - v[j] >= K) {
c.push_back(v[j + 1]);
}
}
assert(v[m - 1] > v[0]);
// assert(dis(v[m - 1], v[0]) == N - v[m - 1] + v[0]);
if (N - (v[m - 1] - v[0]) >= K) {
c.push_back(v[0]);
}
}
assert(i || c.size() == 1);
p = c[0];
A[p] = i;
for (int j = 1; j < K; j++) {
R[(p - j + N) % N]++;
}
}
}
int compare_plants(int x, int y) {
return A[x] > A[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... |