#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
int N, K;
int add(int x, int y) {
x += y;
if (x >= N) x -= N;
return x;
}
int sub(int x, int y) {
x -= y;
if (x < 0) x += N;
return x;
}
int dist(int x, int y) {
return min(sub(x,y), sub(y,x));
}
vector<int> relative, height;
const int MAX_GRAPH = 300;
bool graph[MAX_GRAPH][MAX_GRAPH];
void pop(int cur, int &toPut) {
assert(relative[cur] == 0);
relative[cur] = -1;
rep(delta, 1, K) {
int nxt = sub(cur, delta);
if (relative[nxt] == 0) pop(nxt, toPut);
}
height[cur] = toPut--;
rep(delta, 1, K) {
relative[sub(cur, delta)]--;
}
rep(delta, 1, K) {
if (relative[sub(cur,delta)] == 0) {
pop(sub(cur, delta), toPut);
}
}
}
void init(int _k, std::vector<int> _r) {
K = _k;
relative = _r;
N = _r.size();
//--
height.resize(N);
int toPut = N-1;
for (int i = 0; i < N; ++i) {
if (relative[i] == 0)
pop(i, toPut);
}
if (N <= MAX_GRAPH) {
rep(i, 0, N) rep(j, 0, N) {
graph[i][j] = (dist(i,j) < K && height[i] > height[j]);
}
rep(k, 0, N) rep(i, 0, N) rep(j, 0, N) {
graph[i][j] |= (graph[i][k] && graph[k][j]);
}
}
}
int compare_plants(int x, int y) {
int xy = (height[x] > height[y]);
int yx = (height[y] > height[x]);
if (N <= MAX_GRAPH) {
xy = graph[x][y], yx = graph[y][x];
}
return xy - yx;
}
# |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
38 ms |
3048 KB |
Output is correct |
7 |
Incorrect |
49 ms |
4404 KB |
Output isn't correct |
8 |
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 |
1 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 |
Incorrect |
1 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 |
300 KB |
Output is correct |
3 |
Incorrect |
40 ms |
4776 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
38 ms |
3048 KB |
Output is correct |
7 |
Incorrect |
49 ms |
4404 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |