#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
const int mxn = 2e5 + 100;
int n, k;
int prf[mxn];
int get(int l, int r) {
return prf[r] - (l ? prf[l - 1] : 0);
}
void init(int _k, std::vector<int> r) {
k = _k;
n = r.size();
for (int i = 0; i < n; i++) prf[i] = (i ? prf[i - 1] : 0) + (r[i] == 1 ? -1 : 1);
return;
}
// 1 > : -1 < : 0 ?
int compare_plants(int x, int y) {
int mult = 1;
if (x > y) swap(x, y), mult = -1;
int ans1 = 0, ans2 = 0;
int sum = get(x, y - 1);
if (abs(sum) == y - x) ans1 = sum / abs(sum);
sum = get(x, n - 1);
if (y) sum += get(0, y - 1);
if (abs(sum) == (n - x + y)) ans2 = sum / abs(sum);
int ans = ans1;
if (ans1 == 0) ans = ans2;
else if (ans2 == 0) ans = ans1;
else if (ans1 != ans2) ans = 0;
return ans * mult;
}
# | 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... |