#include "plants.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200200;
int n, k;
int ord[N], deg[N], dpl[N], dpr[N];
void init(int K, vector<int> r) {
n = r.size();
k = K;
if (k == 2) {
for (int i = 0;i < n;i++) {
if (r[i] == 1) deg[(i + 1) % n]++;
else deg[i]++;
}
for (int i = 0;i < n;i++) {
if (deg[i] != 0) continue;
dpl[i] = dpr[i] = 0;
for (int j = 1;j < n;j++) {
dpr[(i - j + n) % n] = j;
if (deg[(i - j + n) % n] == 2) break;
}
for (int j = 1;j < n;j++) {
dpl[(i + j) % n] = j;
if (deg[(i + j) % n] == 2) break;
}
}
return;
}
memset(ord, -1, sizeof ord);
for (int i = n;i >= 1;i--) {
vector<int> v;
for (int j = 0;j < n;j++) {
if (ord[j] == -1 && r[j] == 0) {
v.push_back(j);
}
}
int sz = v.size();
int idx = v[0];
for (int j = 1;j < sz;j++) {
if (v[j] - v[j - 1] >= k) idx = v[j];
}
ord[idx] = i;
for (int j = 1;j < k;j++) {
r[(idx - j + n) % n]--;
}
}
}
bool can(int x, int y) {
int l = dpr[x], r = dpl[x];
if (x + l >= n) {
if (x <= y || y <= x + l - n) return 1;
}
else {
if (x <= y && y <= x + l) return 1;
}
if (x - r < 0) {
if (y <= x || n + x - r <= y) return 1;
}
else {
if (x - r <= y && y <= x) return 1;
}
return 0;
}
int compare_plants(int x, int y) {
if (k != 2) return (ord[x] > ord[y]) ? 1 : -1;
if (can(x, y)) return 1;
if (can(y, x)) return -1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2492 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
29 ms |
6144 KB |
Output is correct |
7 |
Correct |
31 ms |
7516 KB |
Output is correct |
8 |
Correct |
41 ms |
9584 KB |
Output is correct |
9 |
Correct |
47 ms |
9564 KB |
Output is correct |
10 |
Correct |
43 ms |
9564 KB |
Output is correct |
11 |
Correct |
41 ms |
9548 KB |
Output is correct |
12 |
Correct |
40 ms |
9328 KB |
Output is correct |
13 |
Correct |
76 ms |
9420 KB |
Output is correct |
14 |
Correct |
44 ms |
9204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1120 KB |
Output is correct |
5 |
Correct |
1 ms |
1124 KB |
Output is correct |
6 |
Correct |
4 ms |
1376 KB |
Output is correct |
7 |
Correct |
85 ms |
5764 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
5 ms |
1116 KB |
Output is correct |
10 |
Correct |
87 ms |
5972 KB |
Output is correct |
11 |
Correct |
104 ms |
5716 KB |
Output is correct |
12 |
Correct |
62 ms |
6016 KB |
Output is correct |
13 |
Correct |
88 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1120 KB |
Output is correct |
5 |
Correct |
1 ms |
1124 KB |
Output is correct |
6 |
Correct |
4 ms |
1376 KB |
Output is correct |
7 |
Correct |
85 ms |
5764 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
5 ms |
1116 KB |
Output is correct |
10 |
Correct |
87 ms |
5972 KB |
Output is correct |
11 |
Correct |
104 ms |
5716 KB |
Output is correct |
12 |
Correct |
62 ms |
6016 KB |
Output is correct |
13 |
Correct |
88 ms |
5980 KB |
Output is correct |
14 |
Correct |
943 ms |
6200 KB |
Output is correct |
15 |
Execution timed out |
4059 ms |
8796 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
31 ms |
5664 KB |
Output is correct |
4 |
Execution timed out |
4093 ms |
8896 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Incorrect |
0 ms |
1216 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
0 ms |
1116 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2492 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
29 ms |
6144 KB |
Output is correct |
7 |
Correct |
31 ms |
7516 KB |
Output is correct |
8 |
Correct |
41 ms |
9584 KB |
Output is correct |
9 |
Correct |
47 ms |
9564 KB |
Output is correct |
10 |
Correct |
43 ms |
9564 KB |
Output is correct |
11 |
Correct |
41 ms |
9548 KB |
Output is correct |
12 |
Correct |
40 ms |
9328 KB |
Output is correct |
13 |
Correct |
76 ms |
9420 KB |
Output is correct |
14 |
Correct |
44 ms |
9204 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1120 KB |
Output is correct |
19 |
Correct |
1 ms |
1124 KB |
Output is correct |
20 |
Correct |
4 ms |
1376 KB |
Output is correct |
21 |
Correct |
85 ms |
5764 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
5 ms |
1116 KB |
Output is correct |
24 |
Correct |
87 ms |
5972 KB |
Output is correct |
25 |
Correct |
104 ms |
5716 KB |
Output is correct |
26 |
Correct |
62 ms |
6016 KB |
Output is correct |
27 |
Correct |
88 ms |
5980 KB |
Output is correct |
28 |
Correct |
943 ms |
6200 KB |
Output is correct |
29 |
Execution timed out |
4059 ms |
8796 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |