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 pii = pair<int, int>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define debugV(x) cout << #x << " : "; for (auto _ : x) cout << _ << " "; cout << "\n"
int n;
vector<int> val1, val2;
void init(int k, vector<int> r1) {
vector<int> r2 = r1;
n = r1.size(), val1.assign(n, 0), val2.assign(n, 0);
for (int i = n; i >= 1; --i) {
vector<int> check1, check2;
for (int j = 0; j < n; ++j) {
if (r1[j] == 0 and val1[j] == 0) check1.eb(j);
if (r2[j] == 0 and val2[j] == 0) check2.eb(j);
}
// debugV(r1), debugV(r2);
// debugV(val1), debugV(val2);
// cout << check1.size() << " " << check2.size() << "\n";
// debugV(check1), debugV(check2);
int sz1 = check1.size(), sz2 = check2.size();
int ans1 = check1[0], ans2 = check2[0];
for (int j = 0; j < sz1; ++j) {
if (check1[j] + k - 1 < check1[(j+1)%sz1]) ans1 = check1[(j+1)%sz1];
}
for (int j = sz2-1; j >= 0; --j) {
if (check2[j] + k - 1 < check2[(j+1)%sz2]) ans2 = check2[(j+1)%sz2];
}
val1[ans1] = i, val2[ans2] = i;
for (int j = 1; j < k; ++j) --r1[(ans1-j+n)%n], --r2[(ans2-j+n)%n];
}
// debugV(val1), debugV(val2);
return;
}
int compare_plants(int x, int y) {
if (val1[x] > val1[y] and val2[x] < val2[y]) return 0;
if (val1[x] < val1[y] and val2[x] > val2[y]) return 0;
return val1[x] > val1[y] ? 1 : -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... |