This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |