#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int n,k;
vector<int>r,pre,h;
int get(int x,int y){
if(x>y) return 0;
return pre[y]-(x>0?pre[x-1]:0);
}
void init(int K,vector<int>R){
k=K;
r=R;
n=r.size();
pre.resize(n);
pre[0]=r[0];
for(int i=1;i<n;i++){
pre[i]=pre[i-1]+r[i];
}
if(2*k>n){
h.resize(n);
for(int t=n;t>=1;t--){
for(int i=0;i<n;i++){
if(h[i]==0&&r[i]==0){
h[i]=t;
for(int j=1;j<k;j++){
r[(i-j+n)%n]--;
}
break;
}
}
}
}
}
int compare_plants(int x,int y){
if(k==2){
if(get(x,y-1)==0) return 1;
if(get(y,n-1)==n-y&&get(0,x-1)==x) return 1;
if(get(x,y-1)==y-x) return -1;
if(get(y,n-1)==0&&get(0,x-1)==0) return -1;
return 0;
}
if(2*k>n){
if(h[x]>h[y]) return 1;
if(h[x]<h[y]) return -1;
return 0;
}
return 0;
}
# | 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... |