#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int ans,worst;
mt19937 rng(4);
vector<vector<int>> memo;
vector<int> myask(int i){
if(memo[i][0]!=-1)return memo[i];
return memo[i]=ask(i);
}
void dnc(vector<int> v,int good,int lgood,int rgood){
if(good==0)return;
if(v.size()==0)return;
//printf("dnc: {");
//for(int i:v)printf("%d ",i);
//printf("} %d %d %d\n",good,lgood,rgood);
int m=v.size()/2;
vector<int> idk;
for(int i=0;i<v.size();++i){
if(memo[v[i]][0]!=-1&&memo[v[i]][0]+memo[v[i]][1]==worst)idk.push_back(i);
}
//for(int i:idk)printf("%d ",i);printf("\n");
if(idk.size()!=0)m=idk[idk.size()/2];
int s=m;
while(m<v.size()){
vector<int> res=myask(v[m]);
if(res[0]+res[1]==0){
ans=v[m];return;
}
if(res[0]+res[1]==worst){
int mid=m-s;
vector<int> l,r;
for(int i=0;i<s;++i)l.push_back(v[i]);
for(int i=m+1;i<v.size();++i)r.push_back(v[i]);
dnc(l,res[0]-mid-lgood,lgood,res[1]+mid);
dnc(r,res[1]-mid-rgood,res[0]+mid,rgood);
return;
}
else ++m;
}
vector<int> l;
int mid=m-s;
for(int i=0;i<s;++i)l.push_back(v[i]);
dnc(l,good-mid,lgood,rgood+mid);
}
int find_best(int n){
memo.resize(n);
for(int i=0;i<n;++i)memo[i].resize(2,-1);
for(int i=0;i<min(n,500);++i){
int x=rng()%n;
vector<int> res=myask(x);
worst=max(worst,res[0]+res[1]);
if(res[0]+res[1]==0)return x;
}
vector<int> v;
for(int i=0;i<n;++i)v.push_back(i);
dnc(v,worst,0,0);
return ans;
}
Compilation message
prize.cpp: In function 'void dnc(std::vector<int>, int, int, int)':
prize.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<v.size();++i){
| ~^~~~~~~~~
prize.cpp:32:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | while(m<v.size()){
| ~^~~~~~~~~
prize.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=m+1;i<v.size();++i)r.push_back(v[i]);
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
15268 KB |
Output is correct |
2 |
Correct |
20 ms |
15480 KB |
Output is correct |
3 |
Correct |
24 ms |
15300 KB |
Output is correct |
4 |
Correct |
27 ms |
15268 KB |
Output is correct |
5 |
Correct |
23 ms |
15336 KB |
Output is correct |
6 |
Correct |
22 ms |
15252 KB |
Output is correct |
7 |
Correct |
24 ms |
15208 KB |
Output is correct |
8 |
Correct |
23 ms |
15216 KB |
Output is correct |
9 |
Correct |
21 ms |
15260 KB |
Output is correct |
10 |
Correct |
22 ms |
15424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
15212 KB |
Output is correct |
2 |
Correct |
23 ms |
15508 KB |
Output is correct |
3 |
Correct |
23 ms |
15312 KB |
Output is correct |
4 |
Correct |
22 ms |
15164 KB |
Output is correct |
5 |
Correct |
21 ms |
15252 KB |
Output is correct |
6 |
Correct |
20 ms |
15288 KB |
Output is correct |
7 |
Correct |
20 ms |
15260 KB |
Output is correct |
8 |
Correct |
26 ms |
15272 KB |
Output is correct |
9 |
Correct |
22 ms |
15240 KB |
Output is correct |
10 |
Correct |
20 ms |
15480 KB |
Output is correct |
11 |
Correct |
32 ms |
15664 KB |
Output is correct |
12 |
Correct |
38 ms |
15676 KB |
Output is correct |
13 |
Correct |
37 ms |
15660 KB |
Output is correct |
14 |
Correct |
17 ms |
1928 KB |
Output is correct |
15 |
Correct |
76 ms |
15776 KB |
Output is correct |
16 |
Correct |
79 ms |
15768 KB |
Output is correct |
17 |
Correct |
74 ms |
15724 KB |
Output is correct |
18 |
Correct |
79 ms |
15724 KB |
Output is correct |
19 |
Correct |
87 ms |
15780 KB |
Output is correct |
20 |
Correct |
46 ms |
7960 KB |
Output is correct |
21 |
Correct |
72 ms |
15740 KB |
Output is correct |
22 |
Correct |
56 ms |
15828 KB |
Output is correct |
23 |
Correct |
30 ms |
15624 KB |
Output is correct |
24 |
Correct |
33 ms |
15612 KB |
Output is correct |
25 |
Correct |
71 ms |
15856 KB |
Output is correct |
26 |
Correct |
70 ms |
15804 KB |
Output is correct |
27 |
Correct |
25 ms |
15468 KB |
Output is correct |
28 |
Correct |
64 ms |
15660 KB |
Output is correct |
29 |
Correct |
69 ms |
15764 KB |
Output is correct |
30 |
Correct |
80 ms |
15616 KB |
Output is correct |
31 |
Correct |
75 ms |
15624 KB |
Output is correct |
32 |
Correct |
31 ms |
15620 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
78 ms |
15628 KB |
Output is correct |
35 |
Correct |
31 ms |
15596 KB |
Output is correct |
36 |
Correct |
77 ms |
15752 KB |
Output is correct |
37 |
Correct |
32 ms |
15636 KB |
Output is correct |
38 |
Correct |
26 ms |
15592 KB |
Output is correct |
39 |
Correct |
73 ms |
15912 KB |
Output is correct |
40 |
Correct |
75 ms |
15768 KB |
Output is correct |
41 |
Correct |
70 ms |
15628 KB |
Output is correct |
42 |
Correct |
66 ms |
15744 KB |
Output is correct |
43 |
Correct |
82 ms |
15772 KB |
Output is correct |
44 |
Correct |
78 ms |
15640 KB |
Output is correct |
45 |
Correct |
68 ms |
15836 KB |
Output is correct |
46 |
Correct |
88 ms |
15780 KB |
Output is correct |
47 |
Correct |
77 ms |
15788 KB |
Output is correct |
48 |
Correct |
72 ms |
15776 KB |
Output is correct |
49 |
Correct |
72 ms |
15732 KB |
Output is correct |
50 |
Correct |
88 ms |
15768 KB |
Output is correct |
51 |
Correct |
68 ms |
15700 KB |
Output is correct |
52 |
Correct |
73 ms |
15760 KB |
Output is correct |
53 |
Correct |
28 ms |
15592 KB |
Output is correct |
54 |
Correct |
74 ms |
15768 KB |
Output is correct |
55 |
Correct |
71 ms |
15804 KB |
Output is correct |
56 |
Correct |
77 ms |
15720 KB |
Output is correct |
57 |
Correct |
81 ms |
15880 KB |
Output is correct |
58 |
Correct |
69 ms |
15748 KB |
Output is correct |
59 |
Correct |
91 ms |
15692 KB |
Output is correct |
60 |
Correct |
70 ms |
15692 KB |
Output is correct |
61 |
Correct |
28 ms |
15456 KB |
Output is correct |
62 |
Correct |
28 ms |
15492 KB |
Output is correct |
63 |
Correct |
28 ms |
15556 KB |
Output is correct |
64 |
Correct |
29 ms |
15464 KB |
Output is correct |
65 |
Correct |
23 ms |
15420 KB |
Output is correct |
66 |
Correct |
24 ms |
15264 KB |
Output is correct |
67 |
Correct |
24 ms |
15248 KB |
Output is correct |
68 |
Correct |
22 ms |
15264 KB |
Output is correct |
69 |
Correct |
24 ms |
15252 KB |
Output is correct |
70 |
Correct |
24 ms |
15272 KB |
Output is correct |
71 |
Correct |
70 ms |
15744 KB |
Output is correct |
72 |
Correct |
41 ms |
15724 KB |
Output is correct |
73 |
Correct |
76 ms |
15728 KB |
Output is correct |
74 |
Correct |
80 ms |
15716 KB |
Output is correct |
75 |
Correct |
29 ms |
15732 KB |
Output is correct |
76 |
Correct |
71 ms |
15640 KB |
Output is correct |
77 |
Correct |
84 ms |
15728 KB |
Output is correct |
78 |
Correct |
40 ms |
15760 KB |
Output is correct |
79 |
Correct |
54 ms |
15740 KB |
Output is correct |
80 |
Correct |
59 ms |
15740 KB |
Output is correct |
81 |
Correct |
73 ms |
15664 KB |
Output is correct |
82 |
Correct |
80 ms |
15684 KB |
Output is correct |
83 |
Correct |
27 ms |
15676 KB |
Output is correct |
84 |
Correct |
79 ms |
15804 KB |
Output is correct |
85 |
Correct |
55 ms |
15740 KB |
Output is correct |
86 |
Correct |
65 ms |
16088 KB |
Output is correct |
87 |
Correct |
32 ms |
15740 KB |
Output is correct |
88 |
Correct |
48 ms |
16344 KB |
Output is correct |
89 |
Correct |
63 ms |
16172 KB |
Output is correct |
90 |
Correct |
34 ms |
15720 KB |
Output is correct |
91 |
Correct |
61 ms |
16144 KB |
Output is correct |
92 |
Correct |
74 ms |
16280 KB |
Output is correct |
93 |
Correct |
69 ms |
16228 KB |
Output is correct |
94 |
Correct |
68 ms |
16140 KB |
Output is correct |
95 |
Correct |
68 ms |
16072 KB |
Output is correct |
96 |
Correct |
69 ms |
16132 KB |
Output is correct |
97 |
Correct |
65 ms |
16176 KB |
Output is correct |