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;
vector<int> cntGreater; // how many following this are greater than this
vector<int> cntLess; // how many following this are less than this
int n;
void init(int k, std::vector<int> r) {
n = r.size();
cntGreater.resize(n);
int i = 0;
while (r[i] == 1) ++i;
cntGreater[i] = 0;
for (int j = (i-1+n)%n; j != i; j = (j-1+n)%n) {
if (r[j] == 1) cntGreater[j] = cntGreater[(j+1)%n] + 1;
else cntGreater[j] = 0;
}
cntLess.resize(n);
i = 0;
while (r[i] == 0) ++i;
cntLess[i] = 0;
for (int j = (i-1+n)%n; j != i; j = (j-1+n)%n) {
if (r[j] == 0) cntLess[j] = cntLess[(j+1)%n] + 1;
else cntLess[j] = 0;
}
return;
}
int compare_plants(int x, int y) {
if (cntGreater[x] >= y-x) return -1;
if (cntLess[x] >= y-x) return 1;
if (cntGreater[y] >= n+x-y) return 1;
if (cntLess[y] >= n+x-y) return -1;
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... |