# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
768985 | 2023-06-29T04:01:59 Z | ono_de206 | Comparing Plants (IOI20_plants) | C++14 | 0 ms | 0 KB |
#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; void init(int _k, vector<int> r) { k = _k; int 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; }