제출 #524263

#제출 시각아이디문제언어결과실행 시간메모리
524263PurpleCrayonComparing Plants (IOI20_plants)C++17
0 / 100
4074 ms8656 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'; } } } bool can_reach_tree(int x, int y) { if (x == -1) return 0; if (x == y) return 1; return can_reach_tree(par[x], y); } bool can_reach(int x, int y) { if (x == -1) return 0; return can_reach_tree(x, y) || can_reach(chain[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...