#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
/*
* Si h[i] < h[i+1], alors r[i+1] <= r[i]
* Si h[i] > h[i+1] alors r[i+1] >= r[i]
* Donc si on a r[i] != r[i+1] on peut comparer r[i] et r[i+1] !
* r[i+1] > r[i] => h[i+1] < h[i]
* r[i+1] < r[i] => h[i+1] > h[i]
*/
const int MAXN = 2e5;
int k;
int nbPlusGrands[MAXN], cntEq[MAXN][2];
int nbPlantes;
void init(int _k, vector<int> r) {
k = _k;
nbPlantes = r.size();
for (int iPlante = 0; iPlante < nbPlantes; ++iPlante) {
nbPlusGrands[iPlante] = r[iPlante];
}
for (int i = nbPlantes - 1; i >= 0; --i) {
if (i == nbPlantes - 1) {
int x = 1;
while (x < nbPlantes and nbPlusGrands[x - 1] == nbPlusGrands[i])
x++;
cntEq[i][nbPlusGrands[i]] = x;
} else {
cntEq[i][nbPlusGrands[i]] = 1 + cntEq[i + 1][nbPlusGrands[i]];
}
}
return;
}
int compare_plants(int x, int y) {
if (k == 2) {
bool allSame1[2] = {true, true};
bool allSame2[2] = {true, true};
int dis1 = (x < y ? y - x : nbPlantes - x + y);
int dis2 = (y < x ? x - y : nbPlantes - y + x);
for (int b = 0; b < 2; ++b) {
allSame1[b] = cntEq[x][b] >= dis1;
allSame2[b] = cntEq[y][b] >= dis2;
}
/*for (int i = x; i != y; i = (i + 1 == nbPlantes ? 0 : i + 1))
allSame1[!nbPlusGrands[i]] = false;
for (int i = y; i != x; i = (i + 1 == nbPlantes ? 0 : i + 1))
allSame2[!nbPlusGrands[i]] = false;*/
if (allSame1[0] or allSame2[1])
return 1;
else if (allSame1[1] or allSame2[0])
return -1;
return 0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
57 ms |
3984 KB |
Output is correct |
7 |
Correct |
66 ms |
5584 KB |
Output is correct |
8 |
Correct |
91 ms |
9412 KB |
Output is correct |
9 |
Correct |
96 ms |
9564 KB |
Output is correct |
10 |
Correct |
104 ms |
9412 KB |
Output is correct |
11 |
Correct |
87 ms |
9440 KB |
Output is correct |
12 |
Correct |
86 ms |
9408 KB |
Output is correct |
13 |
Correct |
100 ms |
9428 KB |
Output is correct |
14 |
Correct |
96 ms |
9456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
57 ms |
3984 KB |
Output is correct |
7 |
Correct |
66 ms |
5584 KB |
Output is correct |
8 |
Correct |
91 ms |
9412 KB |
Output is correct |
9 |
Correct |
96 ms |
9564 KB |
Output is correct |
10 |
Correct |
104 ms |
9412 KB |
Output is correct |
11 |
Correct |
87 ms |
9440 KB |
Output is correct |
12 |
Correct |
86 ms |
9408 KB |
Output is correct |
13 |
Correct |
100 ms |
9428 KB |
Output is correct |
14 |
Correct |
96 ms |
9456 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |