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;
int n;
vector<int> a;
vector<int> ps;
void init(int k, vector<int> r) {
n = r.size();
a = r;
assert(k == 2);
ps.resize(n);
ps[0] = a[0];
for (int i = 1; i < n; ++i) {
ps[i] = ps[i - 1] + a[i];
}
}
int compare_plants(int x, int y) {
assert(x != y);
int disxy = x < y ? y - x : n - (x - y);
int disyx = y < x ? x - y : n - (y - x);
int mn = min(x, y);
int mx = max(x, y);
int frsum = ps[mx - 1] - (mn ? ps[mn - 1] : 0);
int bcksum = ps[n - 1] - frsum;
//cout << disxy << ' ' << disyx << ' ' << frsum << ' ' << bcksum << endl;
if (x < y) {
if (frsum == 0) return 1;
if (frsum == disxy) return -1;
if (bcksum == 0) return -1;
if (bcksum == disyx) return 1;
return 0;
} else {
if (frsum == 0) return -1;
if (frsum == disxy) return 1;
if (bcksum == 0) return 1;
if (bcksum == disyx) 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... |