Submission #524269

#TimeUsernameProblemLanguageResultExecution timeMemory
524269PurpleCrayonComparing Plants (IOI20_plants)C++17
11 / 100
4096 ms7940 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define sz(v) int(v.size()) vector<int> par, chain; void init(int k, vector<int> r) { int n = sz(r); vector<bool> done(n); par.assign(n, -1); chain.assign(n, -1); auto good_cand = [&](int i) -> bool { if (r[i]) return 0; if (done[i]) return 0; for (int x = i - k + 1; x < i; x++) if (!done[(x + n) % n] && !r[(x + n) % n]) return 0; return 1; }; for (int rep = 0; rep < n; rep++) { int me = -1; for (int i = 0; i < n; i++) if (good_cand(i)) me = i; assert(me != -1); // cerr << "me: " << me << '\n'; 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; // cerr << "set par[ " << (i + n) % n << "] = " << me << '\n'; } for (int i = me + 1; i < me + k; i++) if (!done[i % n]) { chain[i % n] = me; // cerr << "set chain[ " << i % n << "] = " << me << '\n'; } } } set<int> vis; bool can_reach(int x, int y) { if (x == y) return true; vis.insert(x); for (int nxt : {par[x], chain[x]}) if (nxt != -1 && !vis.count(nxt)) { if (can_reach(nxt, y)) return 1; } return 0; } int compare_plants(int x, int y) { vis.clear(); if (can_reach(x, y)) { // y is greater than x return -1; } vis.clear(); if (can_reach(y, x)) { // x is greater than y return 1; } 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...