#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
vector<int> big;
pair<int, vector<int>> differentRight(int a, int b, vector<int> inf)
{
int res = -1;
vector<int> rinf;
while (a <= b)
{
int mid = (a + b) / 2;
vector<int> cinf = ask(mid);
if (cinf == inf)
{
a = mid + 1;
} else
{
res = mid;
rinf = cinf;
b = mid - 1;
}
}
return {res, rinf};
}
pair<int, vector<int>> differentLeft(int a, int b, vector<int> inf)
{
int res = -1;
vector<int> rinf;
while (a <= b)
{
int mid = (a + b) / 2;
vector<int> cinf = ask(mid);
if (cinf == inf)
{
b = mid - 1;
} else
{
res = mid;
rinf = cinf;
a = mid + 1;
}
}
return {res, rinf};
}
int find_best(int N) {
n = N;
if (n <= 5000)
{
int res = -1;
for (int i = 0; i < n; i++)
{
vector<int> v = ask(i);
if (v[0] == 0 && v[1] == 0) res = i;
}
return res;
}
vector<int> needed = {0, 0};
big = {0, 0};
vector<int> inf;
int cur = 0;
inf = ask(cur);
if (inf[0] + inf[1] > big[0] + big[1]) big = inf;
if (inf == needed) return cur;
for (int i = 0; i < 4; i++)
{
auto p1 = differentRight(cur, n - 1, inf);
if (p1.first == -1) break;
cur = p1.first;
inf = p1.second;
if (inf == needed) return cur;
if (inf[0] + inf[1] > big[0] + big[1]) big = inf;
}
int sum = big[0] + big[1];
vector<vector<int>> infAt(n, vector<int>(2));
for (int i = 0; i < n; i += 150)
{
infAt[i] = ask(i);
if (infAt[i] == needed) return i;
}
for (int i = 0; i + 150 < n; i += 150)
{
int l = i;
int r = i + 150;
if (infAt[l] == needed) return l;
if (infAt[r] == needed) return r;
if (infAt[l][0] + infAt[l][1] == infAt[r][0] + infAt[r][1])
{
if (infAt[l][1] - infAt[r][1] == 0) continue;
}
if (infAt[l][0] + infAt[l][1] == sum)
{
auto p1 = differentRight(l, r, infAt[l]);
l = p1.first;
if (l == -1) continue;
infAt[l] = p1.second;
}
if (infAt[r][0] + infAt[r][1] == sum)
{
auto p2 = differentLeft(l, r, infAt[r]);
r = p2.first;
if (r == -1) continue;
infAt[r] = p2.second;
}
if (l != -1 && infAt[l] == needed) return l;
if (r != -1 && infAt[r] == needed) return r;
if (l == -1 || r == -1) continue;
if (r - l <= 1) continue;
if ((infAt[l][0] + infAt[l][1] == infAt[r][0] + infAt[r][1] && infAt[l][1] - infAt[r][1] > 0) || (infAt[l][0] + infAt[l][1] != infAt[r][0] + infAt[r][1]))
{
for (int j = l + 1; j < r; j++)
{
vector<int> cinf = ask(j);
if (cinf[0] == 0 && cinf[1] == 0) return j;
}
}
}
for (int i = 0; i < n; i += 150)
{
if (i + 150 >= n)
{
for (int j = i + 1; j < n; j++)
{
vector<int> cinf = ask(j);
if (cinf == needed) return j;
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
264 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
3 |
Correct |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
276 KB |
Output is correct |
5 |
Correct |
1 ms |
284 KB |
Output is correct |
6 |
Correct |
1 ms |
288 KB |
Output is correct |
7 |
Correct |
1 ms |
284 KB |
Output is correct |
8 |
Correct |
1 ms |
264 KB |
Output is correct |
9 |
Correct |
1 ms |
284 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
264 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
1 ms |
272 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
292 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
36 ms |
11168 KB |
Output is correct |
12 |
Correct |
1 ms |
200 KB |
Output is correct |
13 |
Correct |
33 ms |
11192 KB |
Output is correct |
14 |
Correct |
6 ms |
1352 KB |
Output is correct |
15 |
Correct |
52 ms |
11152 KB |
Output is correct |
16 |
Partially correct |
76 ms |
11160 KB |
Partially correct - number of queries: 6549 |
17 |
Correct |
1 ms |
200 KB |
Output is correct |
18 |
Partially correct |
111 ms |
11156 KB |
Partially correct - number of queries: 7617 |
19 |
Correct |
1 ms |
280 KB |
Output is correct |
20 |
Correct |
39 ms |
5780 KB |
Output is correct |
21 |
Correct |
46 ms |
11176 KB |
Output is correct |
22 |
Correct |
51 ms |
11164 KB |
Output is correct |
23 |
Correct |
1 ms |
200 KB |
Output is correct |
24 |
Correct |
1 ms |
200 KB |
Output is correct |
25 |
Correct |
60 ms |
11164 KB |
Output is correct |
26 |
Correct |
49 ms |
11168 KB |
Output is correct |
27 |
Correct |
26 ms |
11208 KB |
Output is correct |
28 |
Partially correct |
87 ms |
11200 KB |
Partially correct - number of queries: 6596 |
29 |
Partially correct |
61 ms |
11208 KB |
Partially correct - number of queries: 5472 |
30 |
Partially correct |
71 ms |
11152 KB |
Partially correct - number of queries: 7540 |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
36 ms |
11164 KB |
Output is correct |
33 |
Correct |
2 ms |
200 KB |
Output is correct |
34 |
Correct |
51 ms |
11160 KB |
Output is correct |
35 |
Correct |
34 ms |
11168 KB |
Output is correct |
36 |
Correct |
49 ms |
11156 KB |
Output is correct |
37 |
Correct |
30 ms |
11168 KB |
Output is correct |
38 |
Correct |
1 ms |
292 KB |
Output is correct |
39 |
Correct |
68 ms |
11200 KB |
Output is correct |
40 |
Partially correct |
82 ms |
11148 KB |
Partially correct - number of queries: 6658 |
41 |
Correct |
54 ms |
11208 KB |
Output is correct |
42 |
Correct |
70 ms |
11144 KB |
Output is correct |
43 |
Correct |
70 ms |
11160 KB |
Output is correct |
44 |
Correct |
60 ms |
11120 KB |
Output is correct |
45 |
Correct |
51 ms |
11200 KB |
Output is correct |
46 |
Correct |
1 ms |
276 KB |
Output is correct |
47 |
Correct |
61 ms |
11200 KB |
Output is correct |
48 |
Partially correct |
86 ms |
11180 KB |
Partially correct - number of queries: 5832 |
49 |
Correct |
29 ms |
11200 KB |
Output is correct |
50 |
Partially correct |
85 ms |
11200 KB |
Partially correct - number of queries: 7617 |
51 |
Correct |
62 ms |
11176 KB |
Output is correct |
52 |
Correct |
40 ms |
11200 KB |
Output is correct |
53 |
Correct |
32 ms |
11200 KB |
Output is correct |
54 |
Correct |
59 ms |
11200 KB |
Output is correct |
55 |
Correct |
1 ms |
268 KB |
Output is correct |
56 |
Partially correct |
82 ms |
11156 KB |
Partially correct - number of queries: 7613 |
57 |
Partially correct |
61 ms |
11184 KB |
Partially correct - number of queries: 5786 |
58 |
Partially correct |
63 ms |
11172 KB |
Partially correct - number of queries: 5818 |
59 |
Correct |
66 ms |
11208 KB |
Output is correct |
60 |
Correct |
36 ms |
11284 KB |
Output is correct |
61 |
Correct |
34 ms |
11172 KB |
Output is correct |
62 |
Correct |
1 ms |
320 KB |
Output is correct |
63 |
Correct |
34 ms |
11156 KB |
Output is correct |
64 |
Correct |
30 ms |
11168 KB |
Output is correct |
65 |
Correct |
1 ms |
200 KB |
Output is correct |
66 |
Correct |
1 ms |
200 KB |
Output is correct |
67 |
Correct |
1 ms |
200 KB |
Output is correct |
68 |
Correct |
1 ms |
200 KB |
Output is correct |
69 |
Correct |
1 ms |
284 KB |
Output is correct |
70 |
Correct |
1 ms |
320 KB |
Output is correct |
71 |
Partially correct |
89 ms |
11200 KB |
Partially correct - number of queries: 7545 |
72 |
Correct |
29 ms |
11208 KB |
Output is correct |
73 |
Partially correct |
95 ms |
11208 KB |
Partially correct - number of queries: 7454 |
74 |
Partially correct |
105 ms |
11156 KB |
Partially correct - number of queries: 7493 |
75 |
Correct |
32 ms |
11208 KB |
Output is correct |
76 |
Partially correct |
91 ms |
11204 KB |
Partially correct - number of queries: 6609 |
77 |
Partially correct |
48 ms |
11176 KB |
Partially correct - number of queries: 7354 |
78 |
Correct |
26 ms |
11148 KB |
Output is correct |
79 |
Correct |
54 ms |
11196 KB |
Output is correct |
80 |
Partially correct |
111 ms |
11208 KB |
Partially correct - number of queries: 7365 |
81 |
Partially correct |
71 ms |
11336 KB |
Partially correct - number of queries: 7339 |
82 |
Partially correct |
49 ms |
11172 KB |
Partially correct - number of queries: 7309 |
83 |
Correct |
33 ms |
11204 KB |
Output is correct |
84 |
Partially correct |
94 ms |
11188 KB |
Partially correct - number of queries: 6253 |
85 |
Partially correct |
86 ms |
11208 KB |
Partially correct - number of queries: 7314 |
86 |
Correct |
52 ms |
11208 KB |
Output is correct |
87 |
Correct |
40 ms |
11208 KB |
Output is correct |
88 |
Correct |
52 ms |
11208 KB |
Output is correct |
89 |
Correct |
32 ms |
11144 KB |
Output is correct |
90 |
Correct |
2 ms |
200 KB |
Output is correct |
91 |
Correct |
45 ms |
11208 KB |
Output is correct |
92 |
Correct |
1 ms |
204 KB |
Output is correct |
93 |
Partially correct |
74 ms |
11220 KB |
Partially correct - number of queries: 5634 |
94 |
Partially correct |
75 ms |
11208 KB |
Partially correct - number of queries: 6020 |
95 |
Partially correct |
67 ms |
11144 KB |
Partially correct - number of queries: 5786 |
96 |
Partially correct |
77 ms |
11172 KB |
Partially correct - number of queries: 5156 |
97 |
Correct |
1 ms |
200 KB |
Output is correct |