#include "plants.h"
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rank fuck
using namespace std;
using lint = long long;
using llf = long double;
using pi = pair<lint, lint>;
const int MAXN = 200005;
int n, rank[MAXN];
lint L[MAXN], R[MAXN], DL[MAXN], DR[MAXN];
vector<int> lev[MAXN];
int dist(int x, int y){
int d = abs(y - x);
return min(d, n - d);
}
void init(int k, std::vector<int> r) {
n = sz(r);
int layer = 0;
int solved = 0;
while(solved < n){
vector<int> vect;
for(int j=0; j<n; j++){
if(r[j] || rank[j]) continue;
bool claim = true;
for(int x=1; x<=k-1; x++){
if(r[(j-x+n)%n] == 0) claim = false;
}
if(claim) vect.push_back(j);
}
layer++;
solved += sz(vect);
for(auto &j : vect) rank[j] = layer;
for(auto &j : vect){
r[j] = k - 1;
for(int x=1; x<=k-1; x++){
r[(j-x+n)%n]--;
}
}
}
for(int i=0; i<n; i++){
lev[rank[i]].push_back(i);
}
set<int> s;
for(int i=layer; i; i--){
for(auto &j : lev[i]){
auto qq = s.upper_bound(j - k);
auto rr = s.lower_bound(j + k);
if(qq != s.end() && *qq < j) L[j] = (*qq + n) % n;
if(rr != s.begin() && *prev(rr) > j) R[j] = *prev(rr) % n;
DL[j] = DL[L[j]] + (j - L[j] + n) % n;
DR[j] = DR[R[j]] + (R[j] - j + n) % n;
}
for(auto &j : lev[i]){
s.insert(j-n);
s.insert(j);
s.insert(j+n);
}
}
}
int compare_plants(int x, int y) {
if(rank[x] == rank[y]) return 0;
if(rank[x] > rank[y]) return -compare_plants(y, x);
lint st = x - DL[x];
lint ed = x + DR[x];
return st <= y && y <= ed ? 1 : 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
22 ms |
5368 KB |
Output is correct |
7 |
Correct |
456 ms |
9080 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
23 ms |
5376 KB |
Output is correct |
10 |
Correct |
478 ms |
9080 KB |
Output is correct |
11 |
Execution timed out |
4057 ms |
7424 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
22 ms |
5368 KB |
Output is correct |
7 |
Correct |
456 ms |
9080 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
23 ms |
5376 KB |
Output is correct |
10 |
Correct |
478 ms |
9080 KB |
Output is correct |
11 |
Execution timed out |
4057 ms |
7424 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
94 ms |
8312 KB |
Output is correct |
4 |
Execution timed out |
4067 ms |
9132 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |