#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
vector<vi> L;
vi dfs(int u0) {
int n = int(L.size());
vi viz(n, 0);
function<void(int)> dfs0 = [&](int u) {
if(viz[u]) return;
viz[u] = 1;
for(auto it : L[u]) {
if(it != u)
dfs0(it);
}
};
dfs0(u0);
return viz;
}
vector<vi> Reach;
vi perm0, invp0, inv2p0;
void init(int k, vi r) {
int n = int(r.size());
vi active(n, 1);
L.resize(n);
vi Zero;
for(int i = 0; i < n; ++i)
if(!r[i]) Zero.push_back(i);
for(int i = 0; i < n; ++i) {
int v = 0;
for(auto it : Zero) {
int ok = 1;
for(int j = 1; j < k; ++j) {
int p = (it - j + n) % n;
if(active[p] && !r[p]) {
ok = 0;
break;
}
}
if(ok) {
v = it;
break;
}
}
vi Z2;
for(auto it : Zero)
if(it != v) Z2.push_back(it);
Zero = Z2;
active[v] = 0;
for(int j = 1; j < k; ++j) {
int p = (v - j + n) % n;
if(active[p]) {
--r[p];
if(!r[p]) {
L[v].push_back(p);
Zero.push_back(p);
}
}
///^ oare si fara !r[p] e ok rationamentul
int p2 = (v + j) % n;
if(active[p2]) {
L[v].push_back(p2); /// nu puteau fi popite
}
}
perm0.push_back(v);
}
reverse(perm0.begin(), perm0.end());
invp0.resize(n);
inv2p0.resize(n);
for(int i = 0; i < n; ++i) {
invp0[perm0[i]] = i;
}
for(int i = 0; i < n; ++i)
inv2p0[invp0[i]] = i;
for(int i = 0; i < n; ++i)
for(int i = 0; i < n; ++i) {
sort(L[i].begin(), L[i].end());
L[i].resize(unique(L[i].begin(), L[i].end()) - L[i].begin());
}
if(n <= 1) {
for(int i = 0; i < n; ++i)
Reach.push_back(dfs(i));
}
}
int compare_plants(int x, int y) {
if(!Reach.empty()) {
if(Reach[x][y]) return 1;
if(Reach[y][x]) return -1;
return 0;
} else {
if(invp0[x] < invp0[y]) return -1;
return 1;
}
}
# |
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 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2828 ms |
2824 KB |
Output is correct |
7 |
Execution timed out |
4070 ms |
53076 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2828 ms |
2824 KB |
Output is correct |
7 |
Execution timed out |
4070 ms |
53076 KB |
Time limit exceeded |
8 |
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 |
Correct |
104 ms |
3228 KB |
Output is correct |
4 |
Execution timed out |
4042 ms |
11268 KB |
Time limit exceeded |
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 |
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 |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 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 |
348 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 |
- |