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;
vector<int> height(0);
void init(int k, vector<int> r)
{
int n = r.size();
height.assign(n, -2); //-2 = No info, -1 = already candidate
vector<int> candidates(0);
int val = k;
int counter = n;
do
{
for(int i = 0; i < n; i++)
{
if(height[i] == -2 && r[i] == val)
{
candidates.push_back(i);
height[i] = -1;
}
}
if(candidates.empty())
{
val--;
}
}while(candidates.empty());
sort(candidates.begin(), candidates.end());
int index = 0;
while((candidates[index]+k-1)%n >= candidates[(index+1)%candidates.size()])
{
index++;
}
height[candidates[index]] = counter;
counter--;
candidates.erase(candidates.begin()+index);
return;
}
int compare_plants(int x, int y)
{
if(height[x] > height[y])
{
return 1;
}
return -1;
}
# | 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... |