#include<bits/stdc++.h>
#include "plants.h"
using namespace std;
#define ll long long
//#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define inf 0x3f3f3f3f3f3f3f3f
#define pow2(x) (1ll<<(x))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif
const int maxn=200005;
int n,k,sum[maxn],a[maxn];
vector<int> r;
void init(int _k, vector<int> _r){
k=_k;
r=_r;
n=sz(r);
rep(n) sum[i+1]=sum[i]+r[i];
set<int> st;
rep(n) if(r[i]==0) st.insert(i);
int maxx,maxid;
vector<int> vec;
if(n<5005){
bool flag;
rep3(i,n-1,0){
flag=0;
maxx=(*st.begin())-(*st.rbegin())+n;
maxid=*st.begin();
vec.clear();
for(auto j: st) vec.pb(j);
rep2(j,1,sz(vec)) if(vec[j]-vec[j-1]>maxx) maxx=vec[j]-vec[j-1],maxid=vec[j];
a[maxid]=i;
rep1(ii,k-1){
r[(maxid-ii-1+n)%n]--;
if(r[(maxid-ii-1+n)%n]==0) st.insert((maxid-ii-1+n)%n);
}
r[maxid]=n;
st.erase(maxid);
}
}
}
int compare_plants(int x, int y) {
if(k==2){
if(sum[y]-sum[x]==y-x) return -1;
if(sum[y]-sum[x]==0) return 1;
if(sum[n]-sum[y]+sum[x]==n-y+x) return 1;
if(sum[n]-sum[y]+sum[x]==0) return -1;
return 0;
}
return a[x]>a[y]?1:-1;
}
Compilation message
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:43:11: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
43 | bool flag;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
65 ms |
4076 KB |
Output is correct |
7 |
Correct |
85 ms |
5996 KB |
Output is correct |
8 |
Correct |
145 ms |
13420 KB |
Output is correct |
9 |
Correct |
121 ms |
13292 KB |
Output is correct |
10 |
Correct |
126 ms |
13292 KB |
Output is correct |
11 |
Correct |
122 ms |
13804 KB |
Output is correct |
12 |
Correct |
118 ms |
13824 KB |
Output is correct |
13 |
Correct |
137 ms |
18304 KB |
Output is correct |
14 |
Correct |
100 ms |
8812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
13 ms |
492 KB |
Output is correct |
7 |
Correct |
322 ms |
5228 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
13 ms |
492 KB |
Output is correct |
10 |
Correct |
321 ms |
5256 KB |
Output is correct |
11 |
Correct |
331 ms |
5228 KB |
Output is correct |
12 |
Correct |
233 ms |
5392 KB |
Output is correct |
13 |
Correct |
401 ms |
5172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
13 ms |
492 KB |
Output is correct |
7 |
Correct |
322 ms |
5228 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
13 ms |
492 KB |
Output is correct |
10 |
Correct |
321 ms |
5256 KB |
Output is correct |
11 |
Correct |
331 ms |
5228 KB |
Output is correct |
12 |
Correct |
233 ms |
5392 KB |
Output is correct |
13 |
Correct |
401 ms |
5172 KB |
Output is correct |
14 |
Incorrect |
78 ms |
5884 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
80 ms |
4972 KB |
Output is correct |
4 |
Incorrect |
112 ms |
11932 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
380 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
65 ms |
4076 KB |
Output is correct |
7 |
Correct |
85 ms |
5996 KB |
Output is correct |
8 |
Correct |
145 ms |
13420 KB |
Output is correct |
9 |
Correct |
121 ms |
13292 KB |
Output is correct |
10 |
Correct |
126 ms |
13292 KB |
Output is correct |
11 |
Correct |
122 ms |
13804 KB |
Output is correct |
12 |
Correct |
118 ms |
13824 KB |
Output is correct |
13 |
Correct |
137 ms |
18304 KB |
Output is correct |
14 |
Correct |
100 ms |
8812 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
13 ms |
492 KB |
Output is correct |
21 |
Correct |
322 ms |
5228 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
13 ms |
492 KB |
Output is correct |
24 |
Correct |
321 ms |
5256 KB |
Output is correct |
25 |
Correct |
331 ms |
5228 KB |
Output is correct |
26 |
Correct |
233 ms |
5392 KB |
Output is correct |
27 |
Correct |
401 ms |
5172 KB |
Output is correct |
28 |
Incorrect |
78 ms |
5884 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |