#include <iostream>
#include <vector>
#define MAXN 200001
using namespace std;
int ans[MAXN];
void init(int k, vector<int> r) {
int n = r.size();
for (int i=0; i<n; i++) {
int first = 0;
int prev = 0;
int next = -1;
for (int j=0; j<n; j++) {
if (r[j]==0) {
//check wether r[j-1], r[j-2], ..., r[j-k+1] are non-zero
if (first==0) {
first = j;
prev = j;
} else {
next = j;
if (next-prev >= k) {
break;
} else {
prev = j;
}
}
}
}
if (next-prev<k) {
ans[first] = i;
for (int j=0; j<=k-1; j++) {
if (first-j<0) {
first+=n;
r[first-j]--;
} else {
r[first-j]--;
}
}
} else if (next - prev>=k) {
ans[next] = i;
for (int j=0; j<=k-1; j++) {
if (next - j <0) {
next +=n;
r[next - j]--;
} else {
r[next -j]--;
}
}
}
}
}
int compare_plants(int x, int y) {
int a = ans[x];
int b = ans[y];
if (a < b) {
return 1;
} else {
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... |