#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;
void init(int k, vi r) {
int n = int(r.size());
vi active(n, 1);
L.resize(n);
set<int> Zero;
for(int i = 0; i < n; ++i)
if(!r[i]) Zero.insert(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;
}
}
Zero.erase(v);
active[v] = 0;
for(int j = 1; j < k; ++j) {
int p = (v - j + n) % n;
if(active[p]) {
--r[p];
L[v].push_back(p);
if(!r[p]) {
Zero.insert(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
}
}
}
for(int i = 0; i < n; ++i)
Reach.push_back(dfs(i));
}
int compare_plants(int x, int y) {
if(Reach[x][y]) return 1;
if(Reach[y][x]) return -1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
432 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
59 ms |
3972 KB |
Output is correct |
7 |
Correct |
669 ms |
1572124 KB |
Output is correct |
8 |
Runtime error |
824 ms |
2097152 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
1172 ms |
8952 KB |
Output is correct |
7 |
Execution timed out |
4069 ms |
99644 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
1172 ms |
8952 KB |
Output is correct |
7 |
Execution timed out |
4069 ms |
99644 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
76 ms |
20060 KB |
Output is correct |
4 |
Execution timed out |
4062 ms |
15444 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
8 ms |
1628 KB |
Output is correct |
8 |
Correct |
20 ms |
1832 KB |
Output is correct |
9 |
Correct |
13 ms |
1724 KB |
Output is correct |
10 |
Correct |
20 ms |
1884 KB |
Output is correct |
11 |
Correct |
8 ms |
1628 KB |
Output is correct |
12 |
Correct |
10 ms |
1764 KB |
Output is correct |
13 |
Correct |
50 ms |
2204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
428 KB |
Output is correct |
5 |
Correct |
136 ms |
4964 KB |
Output is correct |
6 |
Execution timed out |
4115 ms |
1845800 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
432 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
59 ms |
3972 KB |
Output is correct |
7 |
Correct |
669 ms |
1572124 KB |
Output is correct |
8 |
Runtime error |
824 ms |
2097152 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |