# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
824102 | thimote75 | Comparing Plants (IOI20_plants) | C++14 | 4081 ms | 8636 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>;
template<typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template<typename T>
string to_string (T x) {
string S = "[";
bool first = true;
for (const auto v : x) {
if (!first) S += ", ";
S += to_string(v);
first = false;
}
S += "]";
return S;
}
string to_string( string s) {
return s;
}
string to_string(bool b) {
return to_string((int) b);
}
void dbg_out () { cout << endl; }
template<typename Head, typename... Tail>
void dbg_out (Head H, Tail... T) {
cout << to_string(H) << " ";
dbg_out(T...);
}
#ifdef DEBUG
# define dbg(...) { cout << "(" << #__VA_ARGS__ << "): "; dbg_out(__VA_ARGS__); }
#else
# define dbg(...)
#endif
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) {
idata r0 = r;
int n = r.size();
A.resize(n);
int s = 0;
for (int v = n - 1; v >= 0; v --) {
int p = -1;
int l = -1;
for (int i = 0; i < n; i ++)
if (r[i] == 0)
l = i;
assert(l != -1);
l -= n;
dbg(l, v, r)
for (int i = 0; i < n; i ++) {
if (r[i] != 0) continue ;
int d = i - l;
l = i;
if (d < k) continue ;
p = i;
break ;
}
dbg(p);
r[p] = 1e9;
for (int g = p - 1; g > p - k; g --) {
int u = (g + n) % n;
if (r[u] != 0)
r[u] --;
}
A[p] = v;
}
idata h(n);
for (int i = 0; i < n; i ++) {
int u = 0;
for (int j = i + 1; j < i + k; j ++)
if (A[j % n] > A[i])
u ++;
h[i] = u;
}
//for (int u : h) cout << u << " "; cout << endl;
//for (int u : A) cout << u << " "; cout << endl;
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... |