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 = 1e8;
int n, k;
vector<int> dpL, dpR;
void init_k2(vector<int> r){
dpL.resize(n), dpR.resize(n);
for(int it = 0; it < 2; it++){
for(int i = n-1; i >= 0; i--){
if(r[i]) dpR[i] = dpR[(i+1)%n]+1;
}
for(int i = 0; i < n; i++){
if(!r[(i+n-1)%n]) dpL[i] = dpL[(i+n-1)%n]+1;
}
}
}
vector<int> h;
void init_else(vector<int> r){
h.resize(n);
for(int it = 0; it < n; it++){
for(int i = 0; i < n; i++){
if(r[i] == 0){
bool valid = true;
for(int j = (i-k+1+n)%n; j != i; j=(j+1)%n) if(r[j] == 0) valid = false;
if(!valid) continue;
h[i] = n-it;
r[i] = INF;
for(int j = (i-k+1+n)%n; j != i; j=(j+1)%n) r[j]--;
break;
}
}
}
}
void init(int K, vector<int> r) {
k = K;
n = (int)r.size();
if(k == 2) init_k2(r);
else init_else(r);
}
int compare_k2(int x, int y){
int d1 = (y-x+n)%n;
int d2 = n-d1;
if(dpR[x] >= d1 || dpL[x] >= d2) return -1;
if(dpR[y] >= d2 || dpL[y] >= d1) return 1;
return 0;
}
int compare_else(int x, int y){
if(h[x] < h[y]) return -1;
else return 1;
}
int compare_plants(int x, int y) {
if(k == 2) return compare_k2(x, y);
else return compare_else(x, y);
}
# | 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... |