#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
using ll = long long;
ll n, m, q, k, x, y, a, b, c;
int tc;
vector<ll> vec;
void init(int k, vector<int> r) {
n = r.size();
if (k == 2) {
tc = 1;
vec.push_back(0);
for (int i = 0; i < n; i++) {
vec.push_back(r[i]);
}
for (int i = 0; i < n; i++) {
vec.push_back(r[i]);
}
for (int i = 1; i < 2 * n; i++) {
vec[i] += vec[i - 1];
}
}
else if (k * 2 > n) {
tc = 3;
vec.resize(n);
set<ll> st;
for (int i = 0; i < n; i++) {
if (r[i] == 0) {
st.insert(i);
}
}
ll x = (*st.begin());
for (int i = n - 1; i >= 0; i--) {
vec[x] = i;
st.erase(x);
// cout << x << endl;
for (int j = 1; j < k; j++) {
// cout << j << ' ' << (x - j + n) % n << '\n';
if (r[(x - j + n) % n] == 1) {
st.insert((x - j + n) % n);
}
if (r[(x - j + n) % n] != 0) {
r[(x - j + n) % n]--;
}
}
if (st.size() != 0) {
for (int j : st) {
// cout << j << ' ' << '\n';
if (st.find(j) == (--st.end()) && (*st.begin()) + n - j >= k) {
x = (*st.begin());
break;
}
if (st.find(j) != (--st.end()) && (*st.upper_bound(j)) - j >= k) {
x = (*st.upper_bound(j));
break;
}
}
}
}
}
}
int compare_plants(int x, int y) {
if (tc == 1) {
if (vec[y] - vec[x] == y - x) {
return -1;
}
if (vec[y] - vec[x] == 0) {
return 1;
}
if (vec[(n + x)] - vec[y] == (n + x) - y) {
return 1;
}
if (vec[(n + x)] - vec[y] == 0) {
return -1;
}
return 0;
}
if (tc == 3) {
if (vec[y] > vec[x]) {
return -1;
}
return 1;
}
}
Compilation message
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:88:1: warning: control reaches end of non-void function [-Wreturn-type]
88 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
36 ms |
4144 KB |
Output is correct |
7 |
Correct |
42 ms |
5836 KB |
Output is correct |
8 |
Correct |
52 ms |
11456 KB |
Output is correct |
9 |
Correct |
51 ms |
11456 KB |
Output is correct |
10 |
Correct |
61 ms |
11448 KB |
Output is correct |
11 |
Correct |
59 ms |
12376 KB |
Output is correct |
12 |
Correct |
55 ms |
11976 KB |
Output is correct |
13 |
Correct |
52 ms |
12252 KB |
Output is correct |
14 |
Correct |
56 ms |
11992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
36 ms |
4144 KB |
Output is correct |
7 |
Correct |
42 ms |
5836 KB |
Output is correct |
8 |
Correct |
52 ms |
11456 KB |
Output is correct |
9 |
Correct |
51 ms |
11456 KB |
Output is correct |
10 |
Correct |
61 ms |
11448 KB |
Output is correct |
11 |
Correct |
59 ms |
12376 KB |
Output is correct |
12 |
Correct |
55 ms |
11976 KB |
Output is correct |
13 |
Correct |
52 ms |
12252 KB |
Output is correct |
14 |
Correct |
56 ms |
11992 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |