#include<bits/stdc++.h>
#include "prize.h"
using namespace std;
int N;
int Total=0;
int answer;
void recurtion(int left,int left_ans,int right,int right_ans,int split_answer){
//cout<<left<<" "<<left_ans<<" "<<right<<" "<<right_ans<<" "<<split_answer<<"\n";
if(!split_answer) return;
else{
int M=(left+right)/2;
for(int i=M;i>=left;i--){
auto it = ask(i);
if((it[0]+it[1])==Total){
recurtion(left,left_ans,i,it[1],it[0]-left_ans);
recurtion(M+1,it[0]+(M-i),right,right_ans,it[1]-right_ans-(M-i));
return;
}
else if(it[0]==0 && it[1]==0){
answer=i;
return;
}
}
for(int i=M+1;i<=right;i++){
auto it = ask(i);
if((it[0]+it[1])==Total){
recurtion(i+1,it[0],right,right_ans,it[1]-right_ans);
return;
}
else if(it[0]==0 && it[1]==0){
answer=i;
return;
}
}
}
}
int find_best(int n){
N=n;
//should optimize here!
for(int i=1;i<=min(470,n-1);i++){
auto it = ask(i);
Total = max(Total, it[0] + it[1]);
}
//may get 5 more points!
if(n<=1024){
for(int i=0;i<n;i++){
auto it = ask(i);
if(!(it[0]+it[1])) return i;
}
}
int now=0*1024;
auto it = ask(now);
if(!(it[0]+it[1])) return now;
while((it[0]+it[1])<Total){
if(!(it[0]+it[1])) return now;
now++;
it = ask(now);
}
for(int i=0;i<(n/1024)+1;i++){
int now1 = min((i+1)*1024,n-1);
auto it1 = ask(now1);
if(!(it1[0]+it1[1])) return now1;
while((it1[0]+it1[1])<Total){
if(!(it1[0]+it1[1])) return now1;
now1--;
it1 = ask(now1);
}
recurtion(now,it[0],now1,it1[1],it1[0]-it[0]);
now=now1;
it=it1;
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
6 ms |
208 KB |
Output is correct |
5 |
Correct |
6 ms |
288 KB |
Output is correct |
6 |
Correct |
6 ms |
208 KB |
Output is correct |
7 |
Correct |
6 ms |
288 KB |
Output is correct |
8 |
Correct |
3 ms |
208 KB |
Output is correct |
9 |
Correct |
8 ms |
292 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
288 KB |
Output is correct |
3 |
Correct |
6 ms |
296 KB |
Output is correct |
4 |
Correct |
6 ms |
296 KB |
Output is correct |
5 |
Correct |
5 ms |
208 KB |
Output is correct |
6 |
Correct |
4 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
292 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
9 |
Correct |
6 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
288 KB |
Output is correct |
13 |
Correct |
7 ms |
292 KB |
Output is correct |
14 |
Correct |
9 ms |
208 KB |
Output is correct |
15 |
Partially correct |
21 ms |
208 KB |
Partially correct - number of queries: 5096 |
16 |
Partially correct |
44 ms |
208 KB |
Partially correct - number of queries: 5093 |
17 |
Partially correct |
40 ms |
292 KB |
Partially correct - number of queries: 5100 |
18 |
Partially correct |
34 ms |
292 KB |
Partially correct - number of queries: 5092 |
19 |
Correct |
42 ms |
208 KB |
Output is correct |
20 |
Correct |
24 ms |
208 KB |
Output is correct |
21 |
Partially correct |
33 ms |
292 KB |
Partially correct - number of queries: 5018 |
22 |
Correct |
28 ms |
296 KB |
Output is correct |
23 |
Correct |
7 ms |
208 KB |
Output is correct |
24 |
Correct |
7 ms |
208 KB |
Output is correct |
25 |
Correct |
38 ms |
292 KB |
Output is correct |
26 |
Correct |
36 ms |
284 KB |
Output is correct |
27 |
Correct |
6 ms |
288 KB |
Output is correct |
28 |
Correct |
25 ms |
208 KB |
Output is correct |
29 |
Correct |
28 ms |
292 KB |
Output is correct |
30 |
Partially correct |
32 ms |
292 KB |
Partially correct - number of queries: 5285 |
31 |
Partially correct |
48 ms |
208 KB |
Partially correct - number of queries: 5244 |
32 |
Correct |
8 ms |
208 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Partially correct |
37 ms |
208 KB |
Partially correct - number of queries: 5065 |
35 |
Correct |
6 ms |
208 KB |
Output is correct |
36 |
Partially correct |
42 ms |
292 KB |
Partially correct - number of queries: 5030 |
37 |
Correct |
8 ms |
208 KB |
Output is correct |
38 |
Correct |
7 ms |
292 KB |
Output is correct |
39 |
Partially correct |
51 ms |
208 KB |
Partially correct - number of queries: 5291 |
40 |
Correct |
42 ms |
208 KB |
Output is correct |
41 |
Correct |
48 ms |
252 KB |
Output is correct |
42 |
Correct |
47 ms |
208 KB |
Output is correct |
43 |
Correct |
45 ms |
292 KB |
Output is correct |
44 |
Partially correct |
36 ms |
208 KB |
Partially correct - number of queries: 5076 |
45 |
Correct |
31 ms |
292 KB |
Output is correct |
46 |
Partially correct |
39 ms |
208 KB |
Partially correct - number of queries: 5146 |
47 |
Correct |
38 ms |
292 KB |
Output is correct |
48 |
Partially correct |
38 ms |
208 KB |
Partially correct - number of queries: 5043 |
49 |
Partially correct |
50 ms |
292 KB |
Partially correct - number of queries: 5065 |
50 |
Partially correct |
41 ms |
208 KB |
Partially correct - number of queries: 5125 |
51 |
Partially correct |
37 ms |
208 KB |
Partially correct - number of queries: 5013 |
52 |
Partially correct |
39 ms |
208 KB |
Partially correct - number of queries: 5068 |
53 |
Correct |
5 ms |
208 KB |
Output is correct |
54 |
Partially correct |
18 ms |
280 KB |
Partially correct - number of queries: 5006 |
55 |
Partially correct |
45 ms |
296 KB |
Partially correct - number of queries: 5074 |
56 |
Partially correct |
41 ms |
208 KB |
Partially correct - number of queries: 5130 |
57 |
Partially correct |
47 ms |
208 KB |
Partially correct - number of queries: 5028 |
58 |
Partially correct |
19 ms |
284 KB |
Partially correct - number of queries: 5037 |
59 |
Partially correct |
38 ms |
292 KB |
Partially correct - number of queries: 5106 |
60 |
Partially correct |
34 ms |
292 KB |
Partially correct - number of queries: 5256 |
61 |
Correct |
7 ms |
292 KB |
Output is correct |
62 |
Correct |
6 ms |
208 KB |
Output is correct |
63 |
Correct |
6 ms |
208 KB |
Output is correct |
64 |
Correct |
6 ms |
208 KB |
Output is correct |
65 |
Correct |
5 ms |
208 KB |
Output is correct |
66 |
Correct |
8 ms |
292 KB |
Output is correct |
67 |
Correct |
5 ms |
208 KB |
Output is correct |
68 |
Correct |
6 ms |
288 KB |
Output is correct |
69 |
Correct |
7 ms |
208 KB |
Output is correct |
70 |
Correct |
5 ms |
292 KB |
Output is correct |
71 |
Partially correct |
38 ms |
208 KB |
Partially correct - number of queries: 5499 |
72 |
Correct |
9 ms |
208 KB |
Output is correct |
73 |
Partially correct |
37 ms |
208 KB |
Partially correct - number of queries: 5436 |
74 |
Partially correct |
36 ms |
208 KB |
Partially correct - number of queries: 5463 |
75 |
Correct |
7 ms |
208 KB |
Output is correct |
76 |
Correct |
26 ms |
208 KB |
Output is correct |
77 |
Correct |
19 ms |
336 KB |
Output is correct |
78 |
Correct |
10 ms |
208 KB |
Output is correct |
79 |
Correct |
19 ms |
208 KB |
Output is correct |
80 |
Partially correct |
21 ms |
336 KB |
Partially correct - number of queries: 5037 |
81 |
Partially correct |
19 ms |
336 KB |
Partially correct - number of queries: 5029 |
82 |
Correct |
44 ms |
292 KB |
Output is correct |
83 |
Correct |
6 ms |
208 KB |
Output is correct |
84 |
Correct |
29 ms |
292 KB |
Output is correct |
85 |
Partially correct |
42 ms |
208 KB |
Partially correct - number of queries: 5032 |
86 |
Correct |
19 ms |
208 KB |
Output is correct |
87 |
Correct |
7 ms |
208 KB |
Output is correct |
88 |
Correct |
5 ms |
292 KB |
Output is correct |
89 |
Correct |
11 ms |
208 KB |
Output is correct |
90 |
Correct |
6 ms |
208 KB |
Output is correct |
91 |
Correct |
4 ms |
292 KB |
Output is correct |
92 |
Correct |
11 ms |
208 KB |
Output is correct |
93 |
Correct |
6 ms |
208 KB |
Output is correct |
94 |
Correct |
13 ms |
208 KB |
Output is correct |
95 |
Correct |
9 ms |
208 KB |
Output is correct |
96 |
Correct |
12 ms |
208 KB |
Output is correct |
97 |
Correct |
6 ms |
208 KB |
Output is correct |