#include "plants.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
#define sz(x) ((int)(x).size())
int K, N;
const int nmax = 2e5 + 5;
namespace Queue {
int next[nmax];
int inside[nmax];
set<int> heads;
void insert(int node) {
heads.emplace(node);
inside[node] = 1;
next[node] = -1;
for(int i = (node + 1) % N, d = 1; d < K; d++, i = (i + 1) % N) {
if(inside[i]) {
if(heads.count(i))
heads.erase(i);
next[node] = i;
}
}
for(int i = (node - 1 + N) % N, d = 1; d < K; d++, i = (i - 1 + N) % N) {
if(inside[i]) {
heads.erase(node);
next[i] = node;
}
}
}
vector<int> prune() {
vector<int> rez;
for(auto x : heads)
rez.emplace_back(x), inside[x] = 0;
heads.clear();
for(auto x : rez)
if(next[x] != -1) heads.emplace(x);
return rez;
}
}
vector<int> topsort;
void init(int k__, std::vector<int> r) {
K = k__;
N = sz(r);
topsort.resize(N);
for(int i = 0; i < sz(r); i++) {
if(r[i] == 0) Queue::insert(i);
}
int color = 0;
while(sz(Queue::heads)) {
auto rem = Queue::prune();
++color;
for(auto x : rem) topsort[x] = color;
for(auto x : rem) {
for(int i = (x - 1 + N) % N, d = 1; d < K; d++, i = (i - 1 + N) % N) {
r[i]--;
if(r[i] == 0) Queue::insert(i);
}
}
}
return;
}
int compare_plants(int x, int y) {
return topsort[x] < topsort[y]? 1 : topsort[x] == topsort[y]? 0 : -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Execution timed out |
4096 ms |
348 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
4091 ms |
440 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
4091 ms |
440 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4024 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Execution timed out |
4098 ms |
348 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
4056 ms |
348 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Execution timed out |
4096 ms |
348 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |