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 <bits/stdc++.h>
#include "plants.h"
#define sz(x) (int)x.size()
using namespace std;
int n;
vector<vector<int>> adj;
void init(int k, std::vector<int> r) {
n = sz(r);
adj.resize(n);
vector<bool> vis(n);
for (int i = 0; i < n; i++) {
vector<int> good;
for (int j = 0; j < n; j++) if (!r[j] && !vis[j]) {
bool ok = 1;
for (int z = 1; z < k; z++) {
int idx = j - z;
if (idx < 0) idx += n;
if (!vis[idx] && !r[idx]) {
ok = 0; break;
}
}
if (ok) {
good.emplace_back(j);
}
}
if (good.empty()) break;
for (int v : good) vis[v] = 1;
for (int c : good) for (int j = 0; j < n; j++) if (!vis[j]) adj[c].emplace_back(j);
for (int c : good) {
for (int j = 1; j < k; j++) {
int idx = c - j;
if (idx < 0) idx += n;
r[idx]--;
}
}
}
}
bool reachable(int x, int y) {
vector<bool> vis(n);
auto dfs = [&](auto&& s, int v) -> void {
vis[v] = 1;
for (int u : adj[v]) if (!vis[u]) s(s, u);
};
dfs(dfs, x);
return vis[y];
}
int compare_plants(int x, int y) {
assert(!reachable(x, y) || !reachable(y, x));
return reachable(x, y) ? 1 : reachable(y, x) ? -1 : 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... |