#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, K;
vector<int> R, A;
int dis(int x, int y) {
if (x < y) {
return y - x;
} else {
return N - x + y;
}
}
void init(int k, std::vector<int> r) {
K = k, R = r; N = R.size();
A.resize(N, -1);
for (int i = 0; i < N; i++) {
vector<int> v;
for (int j = 0; j < N; j++) {
if (A[j] == -1 && R[j] == K - 1) {
v.push_back(j);
}
}
int m = v.size(), p;
if (m == 1) {
p = v[0];
} else {
for (int j = 0; j < m; j++) {
if (dis(v[j], v[(j + 1) % m]) >= K) {
p = v[(j + 1) % m];
}
}
}
A[p] = i;
for (int j = 1; j < K; j++) {
R[(p - j + N) % N]++;
}
}
}
int compare_plants(int x, int y) {
return A[x] > A[y] ? 1 : -1;
}
Compilation message
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:34:6: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
34 | A[p] = i;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
340 KB |
Output is correct |
7 |
Correct |
199 ms |
3108 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
364 KB |
Output is correct |
10 |
Correct |
192 ms |
3108 KB |
Output is correct |
11 |
Correct |
157 ms |
3120 KB |
Output is correct |
12 |
Correct |
204 ms |
3392 KB |
Output is correct |
13 |
Correct |
219 ms |
3188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
340 KB |
Output is correct |
7 |
Correct |
199 ms |
3108 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
364 KB |
Output is correct |
10 |
Correct |
192 ms |
3108 KB |
Output is correct |
11 |
Correct |
157 ms |
3120 KB |
Output is correct |
12 |
Correct |
204 ms |
3392 KB |
Output is correct |
13 |
Correct |
219 ms |
3188 KB |
Output is correct |
14 |
Correct |
2500 ms |
3348 KB |
Output is correct |
15 |
Execution timed out |
4070 ms |
5704 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
54 ms |
4468 KB |
Output is correct |
4 |
Execution timed out |
4083 ms |
9880 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |