# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
768986 | ono_de206 | 식물 비교 (IOI20_plants) | C++14 | 0 ms | 0 KiB |
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;
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
// #define int long long
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
vector<int> a, pre;
int n;
void init(int _k, vector<int> r) {
k = _k;
n = r.size();
pre.resize(n * 3);
for(int i = 0; i < 3; i++) {
a.in(a.end(), all(r));
}
pre[0] = a[0];
for(int i = 0; i + 1 < n * 3; i++) {
pre[i + 1] = pre[i] + a[i + 1];
}
}
int compare_plants(int x, int y) {
if(x < y) {
int sum = pre[y - 1] - (x == 0 ? 0 : pre[x - 1]);
if(sum == y - x) return -1;
sum = pre[x + n - 1] - pre[y - 1];
if(sum == x + n - y) return 1;
} else {
int sum = pre[y + n - 1] - pre[x - 1];
if(sum == y + n - x) return -1;
sum = pre[x - 1] - (y == 0 ? 0 : pre[y - 1]);
if(sum == x - y) return 1;
}
return 0;
}