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>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
using namespace std;
const int N = 200'010;
vector<int> A[N];
int n, k;
void init(int k, std::vector<int> r) {
::k = k;
n = r.size();
Loop (_,0,n) {
vector<int> z;
Loop (i,0,n) {
if (r[i] == 0)
z.push_back(i);
}
int p = -1;
Loop (i,0,z.size()) {
if (z[i] - (i == 0? z.back() - n: z[i-1]) >= k) {
p = z[i];
break;
}
}
assert(p != -1);
Loop (ii,p+1,p+k) {
int i = ii%n;
if (r[i] != -1) {
A[i].push_back(p);
}
}
Loop (ii,p-k+1,p) {
int i = (ii+n)%n;
if (r[i] != -1) {
A[i].push_back(p);
r[i]--;
}
}
r[p] = -1;
}
}
bool vis[N];
bool dfs(int v, int dst)
{
if (v == dst)
return 1;
vis[v] = 1;
for (int u : A[v]) {
if (!vis[u] && dfs(u, dst))
return 1;
}
return 0;
}
int compare_plants(int x, int y) {
memset(vis, 0, n);
if (dfs(x, y))
return -1;
memset(vis, 0, n);
if (dfs(y, x))
return 1;
return 0;
}
Compilation message (stderr)
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
| ^
plants.cpp:23:3: note: in expansion of macro 'Loop'
23 | Loop (i,0,z.size()) {
| ^~~~
# | 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... |