# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1222165 | kargneq | Comparing Plants (IOI20_plants) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<int> r;
int n;
void init(int k, const vector<int>& rr) {
r = rr;
n = r.size();
}
int compare_plants(int x, int y) {
// Check if y is one of the next two plants after x (circularly)
int n1 = (x + 1) % n;
int n2 = (x + 2) % n;
if (r[x] == 0 && (y == n1 || y == n2)) return 1; // x is definitely taller
if (r[x] == 2 && (y == n1 || y == n2)) return -1; // x is definitely shorter
// Check if x is one of the next two plants after y (circularly)
int yn1 = (y + 1) % n;
int yn2 = (y + 2) % n;
if (r[y] == 0 && (x == yn1 || x == yn2)) return -1; // y is definitely taller
if (r[y] == 2 && (x == yn1 || x == yn2)) return 1; // y is definitely shorter
return 0; // inconclusive
}