#include "plants.h"
static std:: vector<int> inc,dec,rank;
static int l,m;
// void print(std::vector<int> &v) {for(int elem: v) std::cout << elem << " "; std::cout << std::endl;}
int findMax(int k, std::vector<int> &r) {
int i=2*m-1;
while (r[i%m]!=0) {i--;}
// std::cout << i << std::endl;
int j = i-1;
while (j > i-k) {
if (r[j%m]==0) i = j;
j--;
}
for(int j=i; j>i-k; j--) r[j%m]--;
// std::cout << i%n << std::endl;
// print(r);
return i%m;
}
void init2(int k, std::vector<int> r) {
int n = r.size();
rank.resize(n);
for(int i=n-1; i>=0; i--) {
rank[findMax(k,r)] = i;
// print(rank);
}
return;
}
int compare_plants2(int x, int y) {
if (rank[x]>rank[y]) return 1;
else return -1;
}
void init1(int k, std::vector<int> r) {
int n = r.size();
inc.resize(n); dec.resize(n);
for(int i=0; i<n; i++) {inc[i] = dec[i] = i;}
int s,incVal,decVal;
for(s=2*n-1; s>=0; s--) {
if (r[s%n]==0) incVal = s;
else decVal = s;
inc[s%n] = incVal; dec[s%n] = decVal;
}
return;
}
int compare_plants1(int x, int y) {
if (y <= dec[x] or x+m <= inc[y]) return 1;
else if (y <= inc[x] or x+m <= dec[y]) return -1;
return 0;
}
void init(int k, std::vector<int> r) {
int n = r.size();
m=n; l=k;
if(k==2) init1(k, r);
if(n<=5000 and 2*k>n) init2(k, r);
return;
}
int compare_plants(int x, int y) {
if(l==2) return compare_plants1(x,y);
if(m<=5000 and 2*l>m) return compare_plants2(x,y);
return 0;
}
Compilation message
plants.cpp: In function 'void init1(int, std::vector<int>)':
plants.cpp:41:37: warning: 'decVal' may be used uninitialized in this function [-Wmaybe-uninitialized]
41 | inc[s%n] = incVal; dec[s%n] = decVal;
plants.cpp:41:18: warning: 'incVal' may be used uninitialized in this function [-Wmaybe-uninitialized]
41 | inc[s%n] = incVal; dec[s%n] = decVal;
# |
결과 |
실행 시간 |
메모리 |
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 |
25 ms |
3128 KB |
Output is correct |
7 |
Correct |
43 ms |
3412 KB |
Output is correct |
8 |
Correct |
59 ms |
6484 KB |
Output is correct |
9 |
Correct |
55 ms |
6484 KB |
Output is correct |
10 |
Correct |
39 ms |
6492 KB |
Output is correct |
11 |
Correct |
51 ms |
6604 KB |
Output is correct |
12 |
Correct |
60 ms |
6600 KB |
Output is correct |
13 |
Correct |
72 ms |
6484 KB |
Output is correct |
14 |
Correct |
47 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
432 KB |
Output is correct |
7 |
Correct |
117 ms |
4992 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
532 KB |
Output is correct |
10 |
Correct |
115 ms |
5008 KB |
Output is correct |
11 |
Correct |
108 ms |
4948 KB |
Output is correct |
12 |
Correct |
91 ms |
5248 KB |
Output is correct |
13 |
Correct |
149 ms |
5200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
432 KB |
Output is correct |
7 |
Correct |
117 ms |
4992 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
532 KB |
Output is correct |
10 |
Correct |
115 ms |
5008 KB |
Output is correct |
11 |
Correct |
108 ms |
4948 KB |
Output is correct |
12 |
Correct |
91 ms |
5248 KB |
Output is correct |
13 |
Correct |
149 ms |
5200 KB |
Output is correct |
14 |
Incorrect |
28 ms |
5532 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
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 |
25 ms |
3128 KB |
Output is correct |
7 |
Correct |
43 ms |
3412 KB |
Output is correct |
8 |
Correct |
59 ms |
6484 KB |
Output is correct |
9 |
Correct |
55 ms |
6484 KB |
Output is correct |
10 |
Correct |
39 ms |
6492 KB |
Output is correct |
11 |
Correct |
51 ms |
6604 KB |
Output is correct |
12 |
Correct |
60 ms |
6600 KB |
Output is correct |
13 |
Correct |
72 ms |
6484 KB |
Output is correct |
14 |
Correct |
47 ms |
6748 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
5 ms |
432 KB |
Output is correct |
21 |
Correct |
117 ms |
4992 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
532 KB |
Output is correct |
24 |
Correct |
115 ms |
5008 KB |
Output is correct |
25 |
Correct |
108 ms |
4948 KB |
Output is correct |
26 |
Correct |
91 ms |
5248 KB |
Output is correct |
27 |
Correct |
149 ms |
5200 KB |
Output is correct |
28 |
Incorrect |
28 ms |
5532 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |