# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
823934 | thimote75 | Comparing Plants (IOI20_plants) | C++14 | 4056 ms | 9040 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
using idata = vector<int>;
void shift (idata &r, int count) {
idata h;
for (int i = count; i < r.size(); i ++)
h.push_back(r[i]);
for (int i = 0; i < count; i ++)
h.push_back(r[i]);
r.swap(h);
}
idata A;
void init(int k, idata r) {
int n = r.size();
assert(n < 2 * k);
vector<int> null_points;
for (int i = 0; i < n; i ++) {
if (r[i] == 0) {
r[i] = -1;
null_points.push_back(i);
null_points.push_back(i + n);
}
}
int p0 = 0;
sort(null_points.begin(), null_points.end());
for (int i = 1; i * 2 < null_points.size(); i ++) {
int del = null_points[i] - null_points[i - 1];
if (del < k) continue ;
p0 = i;
break ;
}
p0 = null_points[p0 + (null_points.size() >> 1) - 1] % n;
shift(r, p0 + 1);
A.resize(n);
int s = 0;
for (int v = n - 1; v >= 0; v --) {
int p = 0; int m = 1e9;
for (int i = 0; i < n; i ++) {
if (r[i] > m) continue ;
if (r[i] == m) {
int d = n + p - i;
if (d >= k) continue ;
}
p = i;
m = r[i];
}
r[p] = 1e9;
for (int g = p - 1; g > p - k; g --) r[(g + n) % n] --;
A[(p + p0 + 1) % n] = v;
}
return;
}
int compare_plants(int x, int y) {
int del = A[x] - A[y];
if (del == 0) return 0;
return del / abs(del);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |