#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
int n;
int k;
vector<int> r;
vector<int> prefr;
void genSome();
void init(int k_, std::vector<int> r_) {
k = k_;
r = r_;
n = r.size();
prefr.resize(n + 1);
for (int i = 1; i <= n; i++) {
prefr[i] = prefr[i - 1] + r[i - 1];
}
genSome();
}
int get_sum(int l, int r) {
if (l <= r) {
return prefr[r] - prefr[l];
}
return prefr[n] - prefr[l] + prefr[r];
}
vector<int> h;
void genSome() {
h.resize(n, -1);
vector<int> r2 = r;
for (int asdf = 0; asdf < n; asdf++) {
for (int i = 0; i < n; i++) {
if (r2[i] == 0 && h[i] == -1) {
bool bad = 0;
for (int j = 1; j < k; j++) {
int k = (i - j + n) % n;
if (r2[k] == 0) {
bad = 1;
break;
}
}
if (bad) {
continue;
}
h[i] = n - asdf - 1;
r2[i] = n;
for (int j = 1; j < k; j++) {
int k = (i - j + n) % n;
r2[k]--;
}
break;
}
}
}
}
int compare_plants(int x, int y) {
if (k == 2) {
int a = get_sum(x, y);
int b = get_sum(y, x);
int A = y - x;
if (A < 0)
A += n;
int B = n - A;
if (a == 0) {
return 1;
} else if (a == A) {
return -1;
}
if (b == 0) {
return -1;
} else if (b == B) {
return 1;
}
return 0;
}
if (2 * k > n) {
if (h[x] > h[y]) {
return 1;
} else {
return -1;
}
}
assert(false);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
60 ms |
3052 KB |
Output is correct |
7 |
Correct |
179 ms |
3496 KB |
Output is correct |
8 |
Execution timed out |
4041 ms |
7236 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
420 KB |
Output is correct |
7 |
Correct |
281 ms |
5092 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
11 ms |
332 KB |
Output is correct |
10 |
Correct |
281 ms |
5100 KB |
Output is correct |
11 |
Correct |
205 ms |
5060 KB |
Output is correct |
12 |
Correct |
202 ms |
5220 KB |
Output is correct |
13 |
Correct |
343 ms |
5036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
420 KB |
Output is correct |
7 |
Correct |
281 ms |
5092 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
11 ms |
332 KB |
Output is correct |
10 |
Correct |
281 ms |
5100 KB |
Output is correct |
11 |
Correct |
205 ms |
5060 KB |
Output is correct |
12 |
Correct |
202 ms |
5220 KB |
Output is correct |
13 |
Correct |
343 ms |
5036 KB |
Output is correct |
14 |
Correct |
2458 ms |
5756 KB |
Output is correct |
15 |
Execution timed out |
4038 ms |
10948 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
60 ms |
3052 KB |
Output is correct |
7 |
Correct |
179 ms |
3496 KB |
Output is correct |
8 |
Execution timed out |
4041 ms |
7236 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |