이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |