#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
constexpr static int MXN = 2e5 + 5;
int k, n;
int fw[MXN];
void update(int i, int val) { for (i++;i<MXN;i+=i&(-i)) fw[i] += val; }
int get(int i) { int res = 0; for (i++;i;i-=i&(-i)) res += fw[i]; return res; }
int get(int l, int r) { return get(r) - get(l); }
int v[MXN];
int succ[MXN];
void init(int _k, vector<int> r)
{
debug(r);
n = r.size();
k = _k;
assert(k * 2 > n);
fill(succ, succ + n, -1);
for (int i = 1; i <= n; i++)
{
int prev = -1;
int current = -1;
int first = MXN;
for (int j = 0; j < n; j++)
{
if (v[j])
continue;
int ll = j+1;
int rr = j+k;
int pc = 0;
if (rr >= n)
{
pc += get(ll, n);
pc += get(0, rr);
}
else
{
pc += get(ll, rr);
}
if (pc + r[j] < k-1)
continue;
first = min(first, j);
if (prev != -1 && j - prev >= k)
current = j;
}
if (current == -1)
current = first;
debug(current);
v[current] = i;
update(current, 1);
}
}
int compare_plants(int x, int y)
{
if (v[x] > v[y])
return 1;
if (v[y] > v[x])
return -1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Runtime error |
1 ms |
436 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Runtime error |
1 ms |
436 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |