#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>k0, k1;
int K, n;
vector<int>A;
void init(int k, vector<int> r)
{
K = k;
n = r.size();
if (k == 2)
{
k0 = k1 = vector<int>(n, 0);
for (int t = 0; t < 2; t++)
for (int i = n - 1; i >= 0; i--)
{
if (r[i] == 0)
k0[i] = 1 + k0[(i + 1) % n];
else
k1[i] = 1 + k1[(i + 1) % n];
}
}
if (2 * k > n)
{
A = vector<int>(n, -1);
for (int tt = 0; tt < n; tt++)
{
for (int i = 0; i < n; i++)
{
if (r[i] == 0)
{
int j = i;
bool ok = true;
for (int t = 0; t < k - 1; t++)
{
j--;
if (j < 0)
j += n;
if (r[j] == 0)
{
ok = false;
break;
}
}
if (!ok)
continue;
A[i] = tt;
r[i] = n + 100;
j = i;
for (int t = 0; t < k - 1; t++)
{
j--;
if (j < 0)
j += n;
r[j]--;
}
break;
}
}
}
}
}
int compare_plants(int x, int y)
{
assert(x < y);
if (K == 2)
{
if (k0[x] >= y - x)
return 1;
if (k1[x] >= y - x)
return -1;
if (k0[y] >= n - y + x)
return -1;
if (k1[y] >= n - y + x)
return 1;
return 0;
}
if (!A.empty())
{
if (A[x] < A[y])
return 1;
else
return -1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
64 ms |
3192 KB |
Output is correct |
7 |
Correct |
87 ms |
3448 KB |
Output is correct |
8 |
Correct |
114 ms |
5752 KB |
Output is correct |
9 |
Correct |
110 ms |
5752 KB |
Output is correct |
10 |
Correct |
108 ms |
5784 KB |
Output is correct |
11 |
Correct |
110 ms |
5848 KB |
Output is correct |
12 |
Correct |
109 ms |
5752 KB |
Output is correct |
13 |
Correct |
104 ms |
5752 KB |
Output is correct |
14 |
Correct |
104 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
126 ms |
3192 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
127 ms |
3196 KB |
Output is correct |
11 |
Correct |
110 ms |
3192 KB |
Output is correct |
12 |
Correct |
109 ms |
3320 KB |
Output is correct |
13 |
Correct |
139 ms |
3320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
126 ms |
3192 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
127 ms |
3196 KB |
Output is correct |
11 |
Correct |
110 ms |
3192 KB |
Output is correct |
12 |
Correct |
109 ms |
3320 KB |
Output is correct |
13 |
Correct |
139 ms |
3320 KB |
Output is correct |
14 |
Correct |
743 ms |
3448 KB |
Output is correct |
15 |
Execution timed out |
4065 ms |
4984 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
64 ms |
3192 KB |
Output is correct |
7 |
Correct |
87 ms |
3448 KB |
Output is correct |
8 |
Correct |
114 ms |
5752 KB |
Output is correct |
9 |
Correct |
110 ms |
5752 KB |
Output is correct |
10 |
Correct |
108 ms |
5784 KB |
Output is correct |
11 |
Correct |
110 ms |
5848 KB |
Output is correct |
12 |
Correct |
109 ms |
5752 KB |
Output is correct |
13 |
Correct |
104 ms |
5752 KB |
Output is correct |
14 |
Correct |
104 ms |
5752 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
126 ms |
3192 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
127 ms |
3196 KB |
Output is correct |
25 |
Correct |
110 ms |
3192 KB |
Output is correct |
26 |
Correct |
109 ms |
3320 KB |
Output is correct |
27 |
Correct |
139 ms |
3320 KB |
Output is correct |
28 |
Correct |
743 ms |
3448 KB |
Output is correct |
29 |
Execution timed out |
4065 ms |
4984 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |