#include "plants.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n;
vector<int> edges[MAXN]; // menor pro maior
vector<bool> vis;
bool dfs(int x, int find) {
vis[x] = 1;
if(x == find) return 1;
for(int viz : edges[x]) {
if(!vis[viz] and dfs(viz, find)) return 1;
}
return 0;
}
void init(int k, vector<int> r) {
n = sz(r);
for(int i = 0; i < n; i++) r.pb(r[i]);
for(int t = n; t >= 1; t--) {
vector<int> to_erase;
for(int i = 0, last = -k; i < 2*n; i++) {
if(r[i] != 0) continue;
if(i < n) { last = i; continue; }
if(i - last >= k) to_erase.pb(i);
else if(edges[i%n].empty() or edges[i%n].back() != last) edges[i%n].pb(last%n);
last = i;
}
if(to_erase.empty()) break;
for(int x : to_erase) {
bool ok = 1;
for(int i = x; i > x-k; i--) {
r[i%n]--;
r[i%n + n]--;
if(r[i] == 0) edges[i%n].pb(x%n);
}
}
}
// for(int i = 0; i < n; i++)
// for(int x : edges[i])
// cout << i << " -> " << x << "\n";
return;
}
int compare_plants(int x, int y) {
vis.clear(); vis.resize(n,0);
if(dfs(y,x)) return 1;
vis.clear(); vis.resize(n,0);
if(dfs(x,y)) return -1;
return 0;
}
Compilation message
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:47:9: warning: unused variable 'ok' [-Wunused-variable]
47 | bool ok = 1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
24 ms |
5212 KB |
Output is correct |
7 |
Correct |
3729 ms |
8280 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
23 ms |
5256 KB |
Output is correct |
10 |
Correct |
3656 ms |
8124 KB |
Output is correct |
11 |
Execution timed out |
4067 ms |
61264 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
24 ms |
5212 KB |
Output is correct |
7 |
Correct |
3729 ms |
8280 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
23 ms |
5256 KB |
Output is correct |
10 |
Correct |
3656 ms |
8124 KB |
Output is correct |
11 |
Execution timed out |
4067 ms |
61264 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Execution timed out |
4077 ms |
8796 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
5132 KB |
Output is correct |
5 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Incorrect |
7 ms |
4956 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |