#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
#define pb push_back
std::vector<int> ask(int i);
map<int,vector<int>> mp;
vector<int> ask1(int i)
{
if(mp.find(i)!=mp.end())return mp[i];
return mp[i]=ask(i);
}
int find_best(int n)
{
int ans=-1;
int i=0;
auto it1=ask1(0);
while(1)
{
// cout<<"Starting from "<<i<<endl;
int s=i,e=n;
auto lasp=it1;
if(lasp[0]==0 and lasp[1]==0)
return i;
while(s+1<e){
int mid=(s+e)/2;
auto it=ask1(mid);
// cout<<"Checking "<<mid<<endl;
// cout<<it1[0]<<' '<<it1[1]<<endl;
// cout<<it[0]<<' '<<it[1]<<endl;
if((it1[0]==it[0] and it1[1]==it[1]))
{
s=mid;
}
else{
int cur_sum=it[0]+it[1];
int back_sum=it1[0]+it1[1];
// We want to know if there is any element greater than i in the [i,mid]
if(back_sum<cur_sum)
{
// it is smaller than current element
// can't solve from here
// ll rp=rand()%2;
// if(rp)
// s=mid;
// Recursively call for both side
// or maybe stop binary search
i++;
it1=ask(i);
continue;
}
else{
e=mid;
lasp=it;
}
}
// if((it[0]+it[1])!=((it1[0]+it1[1])))
// {
// e=mid;
// }
// else{
// // if max(a1,a2,a3,..,an) <= k
// // if this is the case
// // then it1[1]==it[1]
// // also it1[0]==it[0]
// s=mid;
// }
}
// cout<<"Solved for "<<i<<' '<<s<<' '<<e<<endl;
if(e==n)
{
break;
}
i=e;
it1=lasp;
}
return i;
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:18:9: warning: unused variable 'ans' [-Wunused-variable]
18 | int ans=-1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
700 KB |
Output is correct |
16 |
Partially correct |
34 ms |
1020 KB |
Partially correct - number of queries: 6894 |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Partially correct |
67 ms |
1028 KB |
Partially correct - number of queries: 8086 |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
7 ms |
600 KB |
Output is correct |
21 |
Correct |
12 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
24 ms |
860 KB |
Output is correct |
26 |
Correct |
22 ms |
840 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Partially correct |
46 ms |
1296 KB |
Partially correct - number of queries: 7618 |
29 |
Partially correct |
26 ms |
1216 KB |
Partially correct - number of queries: 5778 |
30 |
Partially correct |
40 ms |
1404 KB |
Partially correct - number of queries: 8017 |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
13 ms |
508 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
8 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
22 ms |
796 KB |
Output is correct |
40 |
Partially correct |
31 ms |
1104 KB |
Partially correct - number of queries: 6859 |
41 |
Correct |
26 ms |
744 KB |
Output is correct |
42 |
Correct |
26 ms |
1104 KB |
Output is correct |
43 |
Correct |
21 ms |
924 KB |
Output is correct |
44 |
Correct |
22 ms |
852 KB |
Output is correct |
45 |
Correct |
13 ms |
856 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
18 ms |
1204 KB |
Output is correct |
48 |
Partially correct |
44 ms |
984 KB |
Partially correct - number of queries: 5986 |
49 |
Correct |
3 ms |
344 KB |
Output is correct |
50 |
Partially correct |
47 ms |
1200 KB |
Partially correct - number of queries: 8083 |
51 |
Correct |
15 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
344 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
18 ms |
856 KB |
Output is correct |
55 |
Correct |
1 ms |
344 KB |
Output is correct |
56 |
Partially correct |
48 ms |
1160 KB |
Partially correct - number of queries: 8082 |
57 |
Partially correct |
30 ms |
956 KB |
Partially correct - number of queries: 5892 |
58 |
Partially correct |
36 ms |
1200 KB |
Partially correct - number of queries: 5964 |
59 |
Correct |
25 ms |
848 KB |
Output is correct |
60 |
Correct |
29 ms |
844 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
1 ms |
344 KB |
Output is correct |
63 |
Correct |
1 ms |
344 KB |
Output is correct |
64 |
Correct |
1 ms |
344 KB |
Output is correct |
65 |
Correct |
1 ms |
432 KB |
Output is correct |
66 |
Correct |
1 ms |
344 KB |
Output is correct |
67 |
Correct |
1 ms |
428 KB |
Output is correct |
68 |
Incorrect |
2 ms |
344 KB |
answer is not correct |
69 |
Halted |
0 ms |
0 KB |
- |