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> idx;
for (int j = 0; j < n; j++) if (!vis[j]) {
if (!r[j]) idx.emplace_back(j), vis[j] = 1;
}
if (idx.empty()) return;
for (int v : idx) {
for (int j = 1; j < k; j++) {
int u = (v + j) % n;
if (!vis[u]) {
adj[v].emplace_back(u);
}
}
for (int j = 1; j < k; j++) {
int u = (v - j + n) % n;
if (vis[u]) break;
adj[v].emplace_back(u);
}
}
for (int v : idx) {
vis[v] = 1;
for (int j = 1; j < k; j++) {
int u = (v - j + n) % n;
r[u]--;
}
}
}
for (int i = 0; i < n; i++) assert(vis[i]);
}
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... |