#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
int K;
int nxtChain = 0;
int comp[200042];
int lstPos[200042];
int fstPos[200042];
bool isInc[200042];
vector<int> chainId[200042];
// edge from A to B if v[A] > v[B]
void init(int k, vector<int> r) {
int n = (int)r.size();
bool inc = r[0] < r[1];
isInc[0] = inc;
for (int i = 0; i < n; i++) {
//cout << "cur is " << i << '\n';
int nxt = (i + 1) % n;
bool cur = (r[i] < r[nxt]);
if (cur != inc) {
nxtChain++;
//cout << "adding chain " << nxtChain << '\n';
comp[nxtChain] = nxtChain;
isInc[nxtChain] = cur;
fstPos[nxtChain] = i;
}
if (nxt == 0 && (int)chainId[0].size() == 1 && isInc[chainId[0][0]] == cur) {
comp[nxtChain] = chainId[0][0];
break;
}
inc = cur;
chainId[i].push_back(nxtChain);
chainId[nxt].push_back(nxtChain);
lstPos[nxtChain] = nxt;
}
return;
}
int compare_plants(int x, int y) {
for (auto& a: chainId[x]) {
for (auto& b: chainId[y]) {
if (comp[a] == comp[b]) {
/*printf("pos are %d %d\n", x, y);
printf("comp x %d %d\n", a, comp[a]);
printf("comp y %d %d\n", b, comp[b]);*/
if (comp[b] != b) {
if (fstPos[b] == x && (int)chainId[x].size() > 1)
return 0;
if (isInc[comp[b]])
return 1;
return -1;
}
if (isInc[a])
return -1;
return 1;
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |