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 "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 (stderr)
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 |
---|
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... |