# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303093 | 2020-09-19T21:52:49 Z | tutis | Comparing Plants (IOI20_plants) | C++17 | 0 ms | 0 KB |
#include "plants.h" #include <bits/stdc++.h> using namespace std; vector<int>k0, k1; int K; void init(int k, vector<int> r) { K = k; if (k == 2) { int n = r.size(); k0 = k1 = vector<int>(n, 0); for (int t = 0; t < 2; t++) for (int i = n - 1; i >= 0; i--) { if (r[i] == 0) k0[i] = 1 + k0[(i + 1) % n]; else k1[i] = 1 + k1[(i + 1) % n]; } } } int compare_plants(int x, int y) { assert(x < y); if (K == 2) { if (k0[x] >= y - x) return -1; if (k1[x] >= y - x) return 1; if (k0[y] >= n - y + x) return -1; if (k1[y] >= n - y + x) return 1; return 0; } return 0; }