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 ll = long long;
using namespace std;
const int maxn = 1<<18;
int n, k, ord[maxn], ord2[maxn], oh[maxn];
int in(int l, int r, int x) {
if(l >= n) l%=n;
if(r >= n) r%=n;
if(l > r) {
return in(l, n-1, x) || in(0, r, x);
}
return l <= x && x <= r;
}
void ah(int i, int x) {
for(int j = 1; j < k; j++) oh[(i+j)%n]+=x;
}
void init(int K, std::vector<int> r) {
k = K;
n = r.size();
if(k == 2) {
int cur = 0;
for(int j = 0, i = 0; i < n; i++) {
while(r[j]) j = (j+1)%n;
ord[i] = j;
if(i == j) j++;
}
for(int j = 0, i = 0; i < n; i++) {
while(!r[j]) j = (j+1)%n;
ord2[i] = j;
if(i == j) j++;
}
return;
}
for(int i = 0; i < n; i++) if(r[i] == 0) ah(i, 1);
for(int L = n; L; L--) {
int f = 1;
for(int i = 0; f && i < n; i++) if(!oh[i] && r[i] == 0 && !ord[i]) {
ord[i] = L;
ah(i, -1);
for(int j = 1; j < k; j++) {
int pos = (n-j+i)%n;
if(--r[pos] == 0) ah(pos, 1);
}
f = 0;
}
}
return;
}
int compare_plants(int x, int y) {
if(k == 2) {
if(in(x, ord[x], y) || in(y, ord2[y], x)) return -1;
if(in(y, ord[y], x) || in(x, ord2[x], y)) return 1;
return 0;
}
return (ord[x] > ord[y]) - (ord[x] < ord[y]);
}
Compilation message (stderr)
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:22:7: warning: unused variable 'cur' [-Wunused-variable]
22 | int cur = 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... |