# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1049996 | aykhn | Comparing Plants (IOI20_plants) | C++17 | 159 ms | 8416 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;
const int MXN = 5e3 + 5;
int n;
int a[MXN], cnt[MXN], f[MXN];
void init(int k, vector<int> r)
{
n = r.size();
for (int i = 0; i < n; i++) cnt[i] = k - 1;
for (int i = 0; i < n; i++)
{
vector<int> idx;
for (int i = 0; i < n; i++)
{
if (f[i]) continue;
if (r[i] == cnt[i]) idx.push_back(i);
}
if (idx.empty())
{
while (1);
}
int ind = -1;
if (idx.size() == 1) ind = idx[0];
else
{
for (int i = 0; i < idx.size(); i++)
{
if ((idx[(i + 1) % (int)idx.size()] - idx[i] + n) % n >= k)
{
ind = idx[(i + 1) % (int)idx.size()];
break;
}
}
}
if (ind == -1) break;
assert(ind != -1);
a[ind] = i;
f[ind] = 1;
for (int j = (ind - 1 + n) % n; j != (ind - k + n) % n; j = (j - 1 + n) % n) cnt[j]--;
}
}
int compare_plants(int x, int y)
{
return (a[x] > a[y] ? 1 : -1);
}
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... |