#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, K;
vector<int> R, pfs, 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();
pfs.resize(N + 1);
for (int i = 0; i < N; i++) {
pfs[i + 1] = pfs[i] + R[i];
}
A.resize(N, -1);
vector<int> cnt(N, K - 1);
for (int i = 0; i < N; i++) {
vector<int> v;
for (int j = 0; j < N; j++) {
if (A[j] == -1 && R[j] == cnt[j]) {
v.push_back(j);
}
}
int m = v.size(), p;
vector<int> c;
if (m == 1) {
c = {v[0]};
} else {
for (int j = 0; j < m; j++) {
if (dis(v[j], v[(j + 1) % m]) >= K) {
c.push_back(v[(j + 1) % m]);
}
}
}
assert(c.size() == 1);
p = c[0];
A[p] = i;
for (int j = 1; j < K; j++) {
cnt[(p - j + N) % N]--;
}
}
}
int compare_plants(int x, int y) {
if (K == 2) {
if (pfs[y] - pfs[x] == 0) {
return 1;
}
if (pfs[y] - pfs[x] == y - x) {
return -1;
}
if (pfs[N] - pfs[y] + pfs[x] == 0) {
return -1;
}
if (pfs[N] - pfs[y] + pfs[x] == N - y + x) {
return 1;
}
}
return A[x] > A[y] ? 1 : -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |