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 INF = 1 << 30;
int K, N;
vector<int> R;
bool check(int s)
{
int cnt = 0;
for (int i = s - 1; i >= 0 && cnt < K - 1; i--, cnt++)
if (!R[i]) return false;
for (int i = N - 1; cnt < K - 1; i--, cnt++)
if (!R[i]) return false;
cnt = 0;
for (int i = s - 1; i >= 0 && cnt < K - 1; i--, cnt++)
R[i]--;
for (int i = N - 1; cnt < K - 1; i--, cnt++)
R[i]--;
return true;
}
vector<int> H;
void init(int k, vector<int> r)
{
R = r; K = k;
N = (int)r.size();
// Find ordering in O(N²)
H = vector<int>(N);
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (R[j]) continue;
if (check(j))
{
H[j] = N - i;
R[j] = INF;
break;
}
}
}
}
int compare_plants(int x, int y)
{
if (H[x] > H[y])
return 1;
return -1;
}
#ifdef TEST
#include "grader.cpp"
#endif
# | 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... |