#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vc vector
typedef vc<ll> vcll;
#define pr pair
typedef pr<ll,ll> prll;
#define f0r(i,a,n) for ((i)=(a); (i)<(n); (i)++)
#define f1r(i,a,n) for ((i)=(a); (i)<=(n); (i)++)
#define r0f(i,n,a) for ((i)=(n); (i)>(a); (i)--)
#define r1f(i,n,a) for ((i)=(n); (i)>=(a); (i)--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
inline void maxa(ll &a, ll b) { if (a<b) a=b; }
inline void mina(ll &a, ll b) { if (a>b) a=b; }
#define mxN 200'010ll
ll mxnon=474;
vc<prll> rember(mxN, {-1,-1});
ll n;
ll lols;
ll diamond;
/*
inline vc<int> ask(ll i)
{
vc<int> res(2);
printf("i=%lli : ", i);
scanf("%i%i", &res[0], &res[1]);
return res;
}
*/
inline prll asker(ll i)
{
if (rember[i].fi!=-1) return rember[i];
vc<int> res = ask(i);
rember[i].fi=res[0];
rember[i].se=res[1];
return rember[i];
}
inline ll find_lols()
{
ll i;
ll s=-1;
f0r(i,0,mxnon)
{
prll res = asker(i);
if (res.fi+res.se==0)
{
diamond=i;
return -1;
}
maxa(s, res.fi + res.se);
}
// printf("find_lols done\n");
return s;
}
inline ll check_all(ll l, ll r)
{
ll i;
f0r(i,l,r+1)
{
prll res = asker(i);
if (res.fi+res.se==0)
{
diamond=i;
return 1;
}
}
return 0;
}
ll find_diamond(ll l, ll r, prll left_res, prll right_res) // fi is left, se is right (obv.)
{
/*
printf("l: %lli, r: %lli\n", l, r);
printf("left_res: {%lli %lli}\n", left_res.fi, left_res.se);
printf("right_res: {%lli %lli}\n", right_res.fi, right_res.se);
*/
if (r-l<=0) return check_all(l,r);
// pr<bool> dont_check = {0,0};
ll m=(l+r)/2;
ll l1, r1;
// prll res=asker(m); // why the fuck did i write this
prll res;
ll i=m;
while (i<r) // aaa
{
res = asker(i);
l1=res.fi, r1=res.se;
if (l1+r1==lols) break;
if (l1+r1==0)
{
diamond=i;
return 1;
}
i++;
}
if (i==r)
{
res = asker(m);
right_res.fi = right_res.fi - (r+1 - m);
right_res.se = right_res.se + (r+1 - m);
return find_diamond(l, m-1, left_res, right_res);
/*
dont_check.se=1;
i=m-1;
while (i>l)
{
res = asker(i);
l1=res.fi, r1=res.se;
if (l1+r1==lols) break;
if (l1+r1==0)
{
diamond=i;
return 1;
}
i--;
}
if (i==l) return 0;
*/
}
// ll ml1=l1 - (i-m); // eeeeeeeeeeeeeeeeeeeeeeeeeeeeee
// ll left_real=l1-left_res.fi;
/*
if (left_real)
{
if (find_diamond()) return 1;
}
*/
// right_check
ll right_real=r1-right_res.se;
// printf("r1: %lli, right_res.se: %lli\n", r1, right_res.se);
if (right_real)
{
if (find_diamond(i+1, r, asker(i), right_res)) return 1;
}
// left_check
right_res.fi = l1 - (i-m);
ll left_real = right_res.fi - left_res.fi;
if (left_real)
{
right_res.se = r1 + i-m; // bad
if (i!=m) right_res.se--;
if (find_diamond(l, m-1, left_res, right_res)) return 1;
}
return 0;
}
inline ll find_diamond()
{
ll i, j;
prll res1, res2;
f0r(i,0,n)
{
// printf("checking i: %lli\n", i);
res1=asker(i);
if (res1.fi+res1.se==0) return i;
if (res1.fi+res1.se==lols) break;
}
r1f(j,n-1,0)
{
// printf("checking j: %lli\n", j);
res2=asker(j);
if (res2.fi+res2.se==0) return j;
if (res2.fi+res2.se==lols) break;
}
find_diamond(i+1, j-1, res1, res2);
return diamond;
// ll l=0, r=n-1;
}
int find_best(int N)
{
n=N;
if (n==1) return 0; // maybe unec.
mina(mxnon, n);
lols = find_lols();
// lols=5;
return find_diamond();
}
Compilation message
prize.cpp: In function 'll find_diamond(ll, ll, prll, prll)':
prize.cpp:153:2: warning: 'r1' may be used uninitialized in this function [-Wmaybe-uninitialized]
153 | if (right_real)
| ^~
prize.cpp:159:20: warning: 'l1' may be used uninitialized in this function [-Wmaybe-uninitialized]
159 | right_res.fi = l1 - (i-m);
| ~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3416 KB |
Output is correct |
2 |
Correct |
3 ms |
3572 KB |
Output is correct |
3 |
Correct |
3 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3416 KB |
Output is correct |
5 |
Correct |
3 ms |
3576 KB |
Output is correct |
6 |
Correct |
2 ms |
3416 KB |
Output is correct |
7 |
Correct |
3 ms |
3416 KB |
Output is correct |
8 |
Correct |
3 ms |
3416 KB |
Output is correct |
9 |
Correct |
3 ms |
3416 KB |
Output is correct |
10 |
Correct |
3 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3416 KB |
Output is correct |
2 |
Correct |
3 ms |
3568 KB |
Output is correct |
3 |
Correct |
4 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3416 KB |
Output is correct |
5 |
Correct |
4 ms |
3416 KB |
Output is correct |
6 |
Correct |
2 ms |
3672 KB |
Output is correct |
7 |
Correct |
3 ms |
3416 KB |
Output is correct |
8 |
Correct |
3 ms |
3584 KB |
Output is correct |
9 |
Correct |
3 ms |
3616 KB |
Output is correct |
10 |
Correct |
3 ms |
3416 KB |
Output is correct |
11 |
Correct |
4 ms |
3416 KB |
Output is correct |
12 |
Correct |
6 ms |
3416 KB |
Output is correct |
13 |
Correct |
4 ms |
3416 KB |
Output is correct |
14 |
Correct |
8 ms |
3416 KB |
Output is correct |
15 |
Correct |
21 ms |
3416 KB |
Output is correct |
16 |
Correct |
5 ms |
3416 KB |
Output is correct |
17 |
Correct |
5 ms |
3416 KB |
Output is correct |
18 |
Correct |
3 ms |
3412 KB |
Output is correct |
19 |
Correct |
4 ms |
3572 KB |
Output is correct |
20 |
Correct |
11 ms |
3416 KB |
Output is correct |
21 |
Correct |
15 ms |
3416 KB |
Output is correct |
22 |
Correct |
22 ms |
3416 KB |
Output is correct |
23 |
Correct |
4 ms |
3416 KB |
Output is correct |
24 |
Correct |
4 ms |
3416 KB |
Output is correct |
25 |
Correct |
12 ms |
3416 KB |
Output is correct |
26 |
Correct |
14 ms |
3416 KB |
Output is correct |
27 |
Correct |
4 ms |
3416 KB |
Output is correct |
28 |
Correct |
4 ms |
3416 KB |
Output is correct |
29 |
Correct |
5 ms |
3472 KB |
Output is correct |
30 |
Correct |
4 ms |
3416 KB |
Output is correct |
31 |
Correct |
3 ms |
3416 KB |
Output is correct |
32 |
Correct |
4 ms |
3416 KB |
Output is correct |
33 |
Correct |
1 ms |
3416 KB |
Output is correct |
34 |
Correct |
17 ms |
3580 KB |
Output is correct |
35 |
Correct |
4 ms |
3416 KB |
Output is correct |
36 |
Correct |
23 ms |
3416 KB |
Output is correct |
37 |
Correct |
4 ms |
3416 KB |
Output is correct |
38 |
Correct |
3 ms |
3672 KB |
Output is correct |
39 |
Correct |
19 ms |
3416 KB |
Output is correct |
40 |
Correct |
3 ms |
3580 KB |
Output is correct |
41 |
Correct |
12 ms |
3416 KB |
Output is correct |
42 |
Correct |
11 ms |
3416 KB |
Output is correct |
43 |
Correct |
13 ms |
3584 KB |
Output is correct |
44 |
Correct |
17 ms |
3576 KB |
Output is correct |
45 |
Correct |
14 ms |
3416 KB |
Output is correct |
46 |
Correct |
2 ms |
3412 KB |
Output is correct |
47 |
Correct |
17 ms |
3416 KB |
Output is correct |
48 |
Correct |
8 ms |
3416 KB |
Output is correct |
49 |
Correct |
20 ms |
3416 KB |
Output is correct |
50 |
Correct |
3 ms |
3416 KB |
Output is correct |
51 |
Correct |
22 ms |
3416 KB |
Output is correct |
52 |
Correct |
21 ms |
3416 KB |
Output is correct |
53 |
Correct |
3 ms |
3412 KB |
Output is correct |
54 |
Correct |
15 ms |
3416 KB |
Output is correct |
55 |
Correct |
3 ms |
3416 KB |
Output is correct |
56 |
Correct |
3 ms |
3416 KB |
Output is correct |
57 |
Correct |
10 ms |
3416 KB |
Output is correct |
58 |
Correct |
7 ms |
3416 KB |
Output is correct |
59 |
Correct |
11 ms |
3416 KB |
Output is correct |
60 |
Correct |
13 ms |
3416 KB |
Output is correct |
61 |
Correct |
4 ms |
3416 KB |
Output is correct |
62 |
Correct |
4 ms |
3416 KB |
Output is correct |
63 |
Correct |
3 ms |
3416 KB |
Output is correct |
64 |
Correct |
3 ms |
3416 KB |
Output is correct |
65 |
Correct |
3 ms |
3416 KB |
Output is correct |
66 |
Correct |
3 ms |
3416 KB |
Output is correct |
67 |
Correct |
5 ms |
3416 KB |
Output is correct |
68 |
Correct |
3 ms |
3416 KB |
Output is correct |
69 |
Correct |
4 ms |
3416 KB |
Output is correct |
70 |
Correct |
4 ms |
3416 KB |
Output is correct |
71 |
Partially correct |
26 ms |
3416 KB |
Partially correct - number of queries: 5233 |
72 |
Correct |
5 ms |
3416 KB |
Output is correct |
73 |
Partially correct |
25 ms |
3576 KB |
Partially correct - number of queries: 5170 |
74 |
Partially correct |
27 ms |
3416 KB |
Partially correct - number of queries: 5197 |
75 |
Correct |
5 ms |
3416 KB |
Output is correct |
76 |
Correct |
26 ms |
3416 KB |
Output is correct |
77 |
Correct |
26 ms |
3416 KB |
Output is correct |
78 |
Correct |
5 ms |
3416 KB |
Output is correct |
79 |
Correct |
16 ms |
3580 KB |
Output is correct |
80 |
Correct |
24 ms |
3416 KB |
Output is correct |
81 |
Correct |
22 ms |
3416 KB |
Output is correct |
82 |
Correct |
25 ms |
3672 KB |
Output is correct |
83 |
Correct |
3 ms |
3416 KB |
Output is correct |
84 |
Correct |
21 ms |
3576 KB |
Output is correct |
85 |
Correct |
24 ms |
3416 KB |
Output is correct |
86 |
Correct |
4 ms |
3732 KB |
Output is correct |
87 |
Correct |
4 ms |
3580 KB |
Output is correct |
88 |
Correct |
3 ms |
3416 KB |
Output is correct |
89 |
Correct |
3 ms |
3416 KB |
Output is correct |
90 |
Correct |
5 ms |
3680 KB |
Output is correct |
91 |
Correct |
4 ms |
3416 KB |
Output is correct |
92 |
Correct |
3 ms |
3580 KB |
Output is correct |
93 |
Correct |
4 ms |
3416 KB |
Output is correct |
94 |
Correct |
6 ms |
3416 KB |
Output is correct |
95 |
Correct |
6 ms |
3416 KB |
Output is correct |
96 |
Correct |
5 ms |
3416 KB |
Output is correct |
97 |
Correct |
3 ms |
3416 KB |
Output is correct |