This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 ordre[MAXN];
int nbDevant[MAXN];
int nbPlantes;
int disCircle(int x, int y) {
if (x < y)
return y - x;
return nbPlantes - x + y;
}
void init(int _k, vector<int> r) {
k = _k;
nbPlantes = r.size();
for (int iPlante = 0; iPlante < nbPlantes; ++iPlante) {
nbPlusGrands[iPlante] = r[iPlante];
}
if (k == 2) {
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]];
}
}
} else if (2 * k > nbPlantes) {
for (int i = 0; i < nbPlantes; ++i)
nbDevant[i] = k - 1, ordre[i] = -1;
for (int iOrdre = 0; iOrdre < nbPlantes; ++iOrdre) {
vector<int> possibles;
for (int iPlante = 0; iPlante < nbPlantes; ++iPlante)
if (ordre[iPlante] == -1 and nbDevant[iPlante] == nbPlusGrands[iPlante])
possibles.push_back(iPlante);
while (possibles.size() > 1) {
int x = possibles.back();
possibles.pop_back();
int y = possibles.back();
possibles.pop_back();
if (disCircle(x, y) < k)
possibles.push_back(x);
else
possibles.push_back(y);
}
int x = possibles.back();
ordre[x] = iOrdre;
for (int iPlante = 0; iPlante < nbPlantes; ++iPlante)
if (disCircle(iPlante, x) < k and ordre[iPlante] == -1)
nbDevant[iPlante]--;
}
}
}
int compare_plants(int x, int y) {
if (k == 2) {
bool allSame1[2] = {true, true};
bool allSame2[2] = {true, true};
int dis1 = disCircle(x, y);
int dis2 = disCircle(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;
} else if (2 * k > nbPlantes) {
return (ordre[x] < ordre[y] ? -1 : 1);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |