#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-n);
}
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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |