#include "plants.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= l; --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 val[N];
int n, k;
void init(int k, std::vector<int> r) {
::k = k;
n = r.size();
LoopR (x,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-k+1,p) {
int i = (ii+n)%n;
if (r[i] != -1)
r[i]--;
}
r[p] = -1;
val[p] = x;
}
int mx = 0;
while (val[mx] != n-1)
++mx;
vector<int> vec = {mx};
Loop (ii,mx+1,mx+n) {
int i = ii%n;
while (val[vec.back()] < val[i])
vec.pop_back();
A[i].push_back(vec.back());
vec.push_back(i);
}
vec = {mx};
LoopR (ii,mx-n+1,mx) {
int i = (ii+n)%n;
while (val[vec.back()] < val[i])
vec.pop_back();
A[i].push_back(vec.back());
vec.push_back(i);
}
}
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
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:25:3: note: in expansion of macro 'Loop'
25 | Loop (i,0,z.size()) {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
5004 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
5004 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5004 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5004 KB |
Output is correct |
3 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |