#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 |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
2484 ms |
3164 KB |
Output is correct |
7 |
Execution timed out |
4030 ms |
64336 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
2484 ms |
3164 KB |
Output is correct |
7 |
Execution timed out |
4030 ms |
64336 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
4094 ms |
13304 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |