#include <iostream>
#include <vector>
#include <set>
#include "plants.h"
#define pb push_back
using namespace std;
int n;
set<int> zero;
set<int> cur;
set<int>:: iterator it, it2;
int ans[200001];
void init(int k, vector<int> r)
{
int i, j;
n=r.size();
for(i=0;i<n;i++)
r[i]=k-1-r[i];
for(i=0;i<n;i++)
if(r[i]==0)
zero.insert(i), zero.insert(i+n);
for(i=1;i<=n;i++){
it=zero.begin();
while(it!=zero.end() && *it<n){
it2=it, it2++;
if(*it2-*it>=k){
int f=*it2;
if(f>=n) f-=n;
ans[f]=i;
zero.erase(f), zero.erase(f+n);
for(j=0;j<k;j++){
int f2=(f-j);
if(f2<0)
f2+=n;
r[f2]--;
if(r[f2]==0)
zero.insert(f2), zero.insert(f2+n);
}
break;
}
it2=it;
it=zero.lower_bound(*it+k), it--;
if(it==it2) it++;
}
}
}
int compare_plants(int x, int y)
{
if(ans[x]==ans[y])
return 0;
else if(ans[x]>ans[y])
return 1;
return -1;
}
//int main()
//{
// int nn;
// vector<int> in, in2;
// int i, j;
//
// cin >> nn;
// for(i=0;i<nn;i++){
// int x;
// cin >> x;
// in.pb(x), in2.pb(0);
// }
//
// for(i=0;i<nn;i++)
// for(j=1;j<4;j++){
// int f=(i+j)%nn;
// if(in[i]<in[f])
// in2[i]++;
// }
//
// init(4, in2);
// for(i=0;i<n;i++)
// cout << ans[i] << " ";
// cout << endl;
//
// return 0;
//}
//7
// 4 3 5 7 6 1 2
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
154 ms |
3264 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
6 ms |
384 KB |
Output is correct |
10 |
Correct |
156 ms |
3320 KB |
Output is correct |
11 |
Correct |
119 ms |
3192 KB |
Output is correct |
12 |
Correct |
140 ms |
3576 KB |
Output is correct |
13 |
Correct |
174 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
154 ms |
3264 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
6 ms |
384 KB |
Output is correct |
10 |
Correct |
156 ms |
3320 KB |
Output is correct |
11 |
Correct |
119 ms |
3192 KB |
Output is correct |
12 |
Correct |
140 ms |
3576 KB |
Output is correct |
13 |
Correct |
174 ms |
3320 KB |
Output is correct |
14 |
Correct |
895 ms |
3576 KB |
Output is correct |
15 |
Execution timed out |
4054 ms |
5112 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
76 ms |
3192 KB |
Output is correct |
4 |
Execution timed out |
4019 ms |
10944 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |