#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 10;
int n,p[MAX],k,ord[MAX];
set<int> s;
void init(int k, std::vector<int> r) {
n = r.size();
k = k;
for(int i = 0; i < n; i++){
if(r[i] == 0) s.insert(i);
p[i] = r[i];
}
int c = n;
while(s.size()){
int maxi = -1,ant = -1, pri = -1;
for(int x:s){
if(ant== -1) pri = x,ant = x;
else{
if(x-ant>=k){
maxi = x;
break;
}
ant = x;
}
}
if(maxi == -1) maxi = pri;
for(int i = maxi-k+1; i < maxi; i++){
int ind = i>=0?i:i+n;
p[ind]--;
if(p[ind] == 0) s.insert(ind);
}
ord[maxi] = c--;
s.erase(maxi);
}
}
int compare_plants(int x, int y) {
return ord[x] > ord[y]? 1:-1;
}
// 3 4 2 1 5
// k == 3
// 1 0 1 2 0
// 1 0 0 1 -1
// 0 -1 0 1 -1
// -1 -1 0 0 -1
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
57 ms |
5024 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
49 ms |
5240 KB |
Output is correct |
11 |
Correct |
89 ms |
5208 KB |
Output is correct |
12 |
Correct |
46 ms |
5204 KB |
Output is correct |
13 |
Correct |
56 ms |
5200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
57 ms |
5024 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
49 ms |
5240 KB |
Output is correct |
11 |
Correct |
89 ms |
5208 KB |
Output is correct |
12 |
Correct |
46 ms |
5204 KB |
Output is correct |
13 |
Correct |
56 ms |
5200 KB |
Output is correct |
14 |
Correct |
224 ms |
5816 KB |
Output is correct |
15 |
Execution timed out |
4054 ms |
9552 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
32 ms |
4844 KB |
Output is correct |
4 |
Execution timed out |
4067 ms |
11336 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |