#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define lb(v,k) (lower_bound(all(v),k)-v.bein())
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define pb emplace_back
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
const ll inf=1001001001001001001;
int find_best(int n) {
function<vi(vi,ll,ll,ll)> sol=[&](vi v,ll L,ll R,ll S){
vi res;
if(S==0)return res;
if(v.size()==S)return v;
ll md=v.size()/2;
vi srt(v.size());rep(i,v.size())srt[i]=i;
sort(all(srt),[&](ll a,ll b){if(abs(a-md)==abs(b-md))return a<b;return abs(a-md)<abs(b-md);});
vb done(v.size(),false);
for(ll tt:srt){
ll i=v[tt];done[tt]=true;
auto tmp=ask(i);
tmp[0]-=L;tmp[1]-=R;
for(ll x:res)tmp[x>i]--;
if(tmp[0]+tmp[1]!=S-res.size())res.pb(i);
else{
vi va,vb;
rep(j,v.size())if(!done[j]){
if(v[j]<i)va.pb(v[j]);
else vb.pb(v[j]);
}
vi ra=sol(va,L,R+res.size()+tmp[1],tmp[0]);
vi rb=sol(vb,L+res.size()+tmp[0],R,tmp[1]);
for(ll x:ra)res.pb(x);
for(ll x:rb)res.pb(x);
break;
}
}
return res;
};
auto calc=[&](ll k){
ll res=0;
while(k>1){
res+=sqrt(k)+1;
k=sqrt(k);
}
return res;
};
vi al(n);rep(i,n)al[i]=i;
while(al.size()>1){
ll ma=0,tmp;
for(int i=al.size()-1;i>=0;i--){
ll l=calc(i);
if(l+i<=al.size()){
tmp=al.size()-i+1;
break;
}
}
rep(i,min((ll)(al.size()),tmp)){
auto tmp=ask(al[i]);
chmax(ma,(ll)(tmp[0]+tmp[1]));
}
vi nal=sol(al,0,0,ma);
al=nal;
}
return al[0];
}
Compilation message
prize.cpp: In lambda function:
prize.cpp:28:14: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
28 | if(v.size()==S)return v;
| ~~~~~~~~^~~
prize.cpp:38:20: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'long long unsigned int' [-Wsign-compare]
38 | if(tmp[0]+tmp[1]!=S-res.size())res.pb(i);
prize.cpp: In function 'int find_best(int)':
prize.cpp:67:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | if(l+i<=al.size()){
| ~~~^~~~~~~~~~~
prize.cpp:64:11: warning: 'tmp' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | ll ma=0,tmp;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
11328 KB |
Output is correct |
2 |
Correct |
55 ms |
11320 KB |
Output is correct |
3 |
Correct |
67 ms |
11360 KB |
Output is correct |
4 |
Correct |
55 ms |
11364 KB |
Output is correct |
5 |
Correct |
33 ms |
7416 KB |
Output is correct |
6 |
Correct |
60 ms |
11444 KB |
Output is correct |
7 |
Correct |
32 ms |
7496 KB |
Output is correct |
8 |
Correct |
39 ms |
7416 KB |
Output is correct |
9 |
Correct |
59 ms |
11404 KB |
Output is correct |
10 |
Correct |
63 ms |
11360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
11400 KB |
Output is correct |
2 |
Correct |
59 ms |
11368 KB |
Output is correct |
3 |
Correct |
56 ms |
11388 KB |
Output is correct |
4 |
Correct |
58 ms |
11376 KB |
Output is correct |
5 |
Correct |
33 ms |
7488 KB |
Output is correct |
6 |
Correct |
56 ms |
11384 KB |
Output is correct |
7 |
Correct |
33 ms |
7488 KB |
Output is correct |
8 |
Correct |
34 ms |
7424 KB |
Output is correct |
9 |
Correct |
58 ms |
11320 KB |
Output is correct |
10 |
Correct |
62 ms |
11312 KB |
Output is correct |
11 |
Correct |
158 ms |
11596 KB |
Output is correct |
12 |
Correct |
172 ms |
11644 KB |
Output is correct |
13 |
Correct |
161 ms |
11640 KB |
Output is correct |
14 |
Correct |
31 ms |
1520 KB |
Output is correct |
15 |
Correct |
235 ms |
11672 KB |
Output is correct |
16 |
Correct |
245 ms |
11664 KB |
Output is correct |
17 |
Correct |
240 ms |
11660 KB |
Output is correct |
18 |
Correct |
243 ms |
11636 KB |
Output is correct |
19 |
Correct |
232 ms |
11608 KB |
Output is correct |
20 |
Correct |
120 ms |
5968 KB |
Output is correct |
21 |
Correct |
252 ms |
11708 KB |
Output is correct |
22 |
Correct |
253 ms |
11616 KB |
Output is correct |
23 |
Correct |
122 ms |
11644 KB |
Output is correct |
24 |
Correct |
149 ms |
11592 KB |
Output is correct |
25 |
Correct |
246 ms |
11604 KB |
Output is correct |
26 |
Correct |
229 ms |
11632 KB |
Output is correct |
27 |
Correct |
103 ms |
11660 KB |
Output is correct |
28 |
Correct |
238 ms |
11684 KB |
Output is correct |
29 |
Correct |
205 ms |
11672 KB |
Output is correct |
30 |
Correct |
235 ms |
11612 KB |
Output is correct |
31 |
Correct |
236 ms |
11608 KB |
Output is correct |
32 |
Correct |
154 ms |
11620 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
225 ms |
11780 KB |
Output is correct |
35 |
Correct |
127 ms |
11632 KB |
Output is correct |
36 |
Correct |
253 ms |
11624 KB |
Output is correct |
37 |
Correct |
148 ms |
11680 KB |
Output is correct |
38 |
Correct |
124 ms |
11516 KB |
Output is correct |
39 |
Correct |
263 ms |
11728 KB |
Output is correct |
40 |
Correct |
248 ms |
11632 KB |
Output is correct |
41 |
Correct |
249 ms |
11676 KB |
Output is correct |
42 |
Correct |
240 ms |
11604 KB |
Output is correct |
43 |
Correct |
247 ms |
11796 KB |
Output is correct |
44 |
Correct |
254 ms |
11760 KB |
Output is correct |
45 |
Correct |
221 ms |
11688 KB |
Output is correct |
46 |
Correct |
248 ms |
11676 KB |
Output is correct |
47 |
Correct |
237 ms |
11640 KB |
Output is correct |
48 |
Correct |
251 ms |
11656 KB |
Output is correct |
49 |
Correct |
241 ms |
11716 KB |
Output is correct |
50 |
Correct |
253 ms |
11508 KB |
Output is correct |
51 |
Correct |
259 ms |
11624 KB |
Output is correct |
52 |
Correct |
245 ms |
11612 KB |
Output is correct |
53 |
Correct |
124 ms |
11616 KB |
Output is correct |
54 |
Correct |
257 ms |
11624 KB |
Output is correct |
55 |
Correct |
237 ms |
11664 KB |
Output is correct |
56 |
Correct |
232 ms |
11780 KB |
Output is correct |
57 |
Correct |
269 ms |
11604 KB |
Output is correct |
58 |
Correct |
242 ms |
11648 KB |
Output is correct |
59 |
Correct |
254 ms |
11676 KB |
Output is correct |
60 |
Correct |
233 ms |
11676 KB |
Output is correct |
61 |
Correct |
129 ms |
11524 KB |
Output is correct |
62 |
Correct |
135 ms |
11512 KB |
Output is correct |
63 |
Correct |
123 ms |
11644 KB |
Output is correct |
64 |
Correct |
127 ms |
11580 KB |
Output is correct |
65 |
Correct |
79 ms |
11616 KB |
Output is correct |
66 |
Correct |
59 ms |
11356 KB |
Output is correct |
67 |
Correct |
76 ms |
11388 KB |
Output is correct |
68 |
Correct |
61 ms |
11396 KB |
Output is correct |
69 |
Correct |
65 ms |
11352 KB |
Output is correct |
70 |
Correct |
60 ms |
11328 KB |
Output is correct |
71 |
Correct |
241 ms |
11696 KB |
Output is correct |
72 |
Correct |
168 ms |
11628 KB |
Output is correct |
73 |
Correct |
233 ms |
11672 KB |
Output is correct |
74 |
Correct |
228 ms |
11712 KB |
Output is correct |
75 |
Correct |
118 ms |
11552 KB |
Output is correct |
76 |
Correct |
228 ms |
11680 KB |
Output is correct |
77 |
Correct |
275 ms |
11604 KB |
Output is correct |
78 |
Correct |
159 ms |
11632 KB |
Output is correct |
79 |
Correct |
232 ms |
11616 KB |
Output is correct |
80 |
Correct |
240 ms |
11680 KB |
Output is correct |
81 |
Correct |
255 ms |
11744 KB |
Output is correct |
82 |
Correct |
263 ms |
11716 KB |
Output is correct |
83 |
Correct |
123 ms |
11660 KB |
Output is correct |
84 |
Correct |
277 ms |
11592 KB |
Output is correct |
85 |
Correct |
240 ms |
11644 KB |
Output is correct |
86 |
Correct |
86 ms |
11380 KB |
Output is correct |
87 |
Correct |
82 ms |
11584 KB |
Output is correct |
88 |
Correct |
89 ms |
11344 KB |
Output is correct |
89 |
Correct |
87 ms |
11504 KB |
Output is correct |
90 |
Correct |
86 ms |
11632 KB |
Output is correct |
91 |
Correct |
94 ms |
11584 KB |
Output is correct |
92 |
Correct |
81 ms |
11372 KB |
Output is correct |
93 |
Correct |
152 ms |
11660 KB |
Output is correct |
94 |
Correct |
145 ms |
11616 KB |
Output is correct |
95 |
Correct |
144 ms |
11584 KB |
Output is correct |
96 |
Correct |
156 ms |
11600 KB |
Output is correct |
97 |
Correct |
83 ms |
11328 KB |
Output is correct |