Submission #524259

#TimeUsernameProblemLanguageResultExecution timeMemory
524259PurpleCrayonComparing Plants (IOI20_plants)C++17
0 / 100
1 ms296 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define sz(v) int(v.size()) vector<int> par; void init(int k, vector<int> r) { int n = sz(r); vector<bool> done(n); par.assign(n, -1); auto get_cand = [&]() -> int { // find a zero that isn't covered by another vector<int> cand; cand.reserve(n); for (int i = 0; i < n; i++) if (r[i] == 0 && !done[i]) { cand.push_back(i); } for (int i = 0; i < sz(cand); i++) { int x = cand[i]; int prv = cand[sz(cand) - 1]; int dist = n - prv + x; if (i) { prv = cand[i - 1]; dist = x - prv; } if (dist >= k) { return x; } } assert(false); }; for (int rep = 0; rep < n; rep++) { int me = get_cand(); done[me] = 1; for (int i = me - k + 1; i < me; i++) if (!done[(i + n) % n]) { r[(i + n) % n]--; par[(i + n) % n] = me; } } } bool can_reach(int x, int y) { if (x == -1) return 0; if (x == y) return 1; return can_reach(par[x], y); } int compare_plants(int x, int y) { if (can_reach(x, y)) { // y is greater than x return -1; } else if (can_reach(y, x)) { // x is greater than y return 1; } else { // impossible to determine return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...