#include "prize.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cassert>
#include <random>
using namespace std;
#define rep(i,n)for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
typedef pair<int, int> P;
mt19937 mt_rand(114514);
int mp = 0;
P cache[200000];
int Q=0;
P query(int x) {
if (cache[x] != P(-1, -1)) return cache[x];
Q++;
assert(Q<=10000);
//if(Q%100==0)cout<<"Q="<<Q<<"\n";
vector<int> ret = ask(x);
return cache[x] = {ret[0], ret[1]};
}
int solve(int l, int r, int num, int left) {
if (num <= 0) return -1;
//cout<<"solve("<<l<<","<<r<<", num="<<num<<")\n";
for (int mid=(l+r)/2+1; mid<=r; mid++) {
P ret = query(mid);
if (ret._1+ret._2 == 0) return mid;
if (ret._1+ret._2 != mp) continue;
if (mid > l) {
int o = solve(l, mid-1, ret._1-left, left);
if (o != -1) return o;
}
if (mid < r) {
int o = solve(mid+1, r, num-(ret._1-left), ret._1);
if (o != -1) return o;
}
return -1;
}
for (int mid=(l+r)/2; mid>=l; mid--) {
P ret = query(mid);
if (ret._1+ret._2 == 0) return mid;
if (ret._1+ret._2 != mp) continue;
if (mid > l) {
int o = solve(l, mid-1, ret._1-left, left);
if (o != -1) return o;
}
if (mid < r) {
int o = solve(mid+1, r, num-(ret._1-left), ret._1);
if (o != -1) return o;
}
return -1;
}
return -1;
}
int find_best(int N) {
rep(i, N) cache[i] = P(-1, -1);
rep(i, 30) {
P ret = query(mt_rand()%N);
mp = max(mp, ret._1+ret._2);
}
//cout<<"mp="<<mp<<"\n";
assert(mp < 500);
int r = solve(0, N-1, mp, 0);
assert(r != -1);
return r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
5 ms |
1912 KB |
Output is correct |
3 |
Correct |
5 ms |
1948 KB |
Output is correct |
4 |
Correct |
4 ms |
1956 KB |
Output is correct |
5 |
Correct |
5 ms |
2004 KB |
Output is correct |
6 |
Correct |
5 ms |
2004 KB |
Output is correct |
7 |
Correct |
5 ms |
2004 KB |
Output is correct |
8 |
Correct |
4 ms |
2120 KB |
Output is correct |
9 |
Correct |
5 ms |
2120 KB |
Output is correct |
10 |
Correct |
5 ms |
2156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2156 KB |
Output is correct |
2 |
Correct |
5 ms |
2156 KB |
Output is correct |
3 |
Correct |
5 ms |
2156 KB |
Output is correct |
4 |
Correct |
5 ms |
2156 KB |
Output is correct |
5 |
Correct |
6 ms |
2156 KB |
Output is correct |
6 |
Correct |
7 ms |
2156 KB |
Output is correct |
7 |
Correct |
3 ms |
2156 KB |
Output is correct |
8 |
Correct |
6 ms |
2156 KB |
Output is correct |
9 |
Correct |
5 ms |
2156 KB |
Output is correct |
10 |
Correct |
7 ms |
2156 KB |
Output is correct |
11 |
Correct |
9 ms |
2156 KB |
Output is correct |
12 |
Correct |
5 ms |
2156 KB |
Output is correct |
13 |
Correct |
11 ms |
2156 KB |
Output is correct |
14 |
Correct |
4 ms |
2156 KB |
Output is correct |
15 |
Correct |
10 ms |
2156 KB |
Output is correct |
16 |
Correct |
40 ms |
2156 KB |
Output is correct |
17 |
Correct |
5 ms |
2156 KB |
Output is correct |
18 |
Correct |
63 ms |
2156 KB |
Output is correct |
19 |
Correct |
5 ms |
2156 KB |
Output is correct |
20 |
Correct |
18 ms |
2156 KB |
Output is correct |
21 |
Correct |
24 ms |
2156 KB |
Output is correct |
22 |
Correct |
10 ms |
2156 KB |
Output is correct |
23 |
Correct |
3 ms |
2156 KB |
Output is correct |
24 |
Correct |
4 ms |
2156 KB |
Output is correct |
25 |
Correct |
14 ms |
2156 KB |
Output is correct |
26 |
Correct |
27 ms |
2156 KB |
Output is correct |
27 |
Correct |
5 ms |
2156 KB |
Output is correct |
28 |
Correct |
37 ms |
2156 KB |
Output is correct |
29 |
Correct |
50 ms |
2156 KB |
Output is correct |
30 |
Correct |
48 ms |
2156 KB |
Output is correct |
31 |
Correct |
5 ms |
2156 KB |
Output is correct |
32 |
Correct |
7 ms |
2156 KB |
Output is correct |
33 |
Correct |
2 ms |
2156 KB |
Output is correct |
34 |
Correct |
20 ms |
2156 KB |
Output is correct |
35 |
Correct |
7 ms |
2156 KB |
Output is correct |
36 |
Correct |
21 ms |
2156 KB |
Output is correct |
37 |
Correct |
6 ms |
2156 KB |
Output is correct |
38 |
Correct |
5 ms |
2156 KB |
Output is correct |
39 |
Correct |
29 ms |
2156 KB |
Output is correct |
40 |
Correct |
55 ms |
2156 KB |
Output is correct |
41 |
Correct |
15 ms |
2156 KB |
Output is correct |
42 |
Correct |
30 ms |
2156 KB |
Output is correct |
43 |
Correct |
26 ms |
2156 KB |
Output is correct |
44 |
Correct |
20 ms |
2156 KB |
Output is correct |
45 |
Correct |
21 ms |
2156 KB |
Output is correct |
46 |
Correct |
5 ms |
2156 KB |
Output is correct |
47 |
Correct |
19 ms |
2156 KB |
Output is correct |
48 |
Correct |
35 ms |
2156 KB |
Output is correct |
49 |
Correct |
11 ms |
2156 KB |
Output is correct |
50 |
Correct |
52 ms |
2156 KB |
Output is correct |
51 |
Correct |
30 ms |
2156 KB |
Output is correct |
52 |
Correct |
5 ms |
2156 KB |
Output is correct |
53 |
Correct |
5 ms |
2156 KB |
Output is correct |
54 |
Correct |
26 ms |
2156 KB |
Output is correct |
55 |
Correct |
4 ms |
2156 KB |
Output is correct |
56 |
Correct |
57 ms |
2156 KB |
Output is correct |
57 |
Correct |
40 ms |
2156 KB |
Output is correct |
58 |
Correct |
48 ms |
2156 KB |
Output is correct |
59 |
Correct |
38 ms |
2156 KB |
Output is correct |
60 |
Correct |
28 ms |
2156 KB |
Output is correct |
61 |
Correct |
8 ms |
2156 KB |
Output is correct |
62 |
Correct |
6 ms |
2156 KB |
Output is correct |
63 |
Correct |
6 ms |
2156 KB |
Output is correct |
64 |
Correct |
5 ms |
2156 KB |
Output is correct |
65 |
Correct |
5 ms |
2156 KB |
Output is correct |
66 |
Correct |
6 ms |
2156 KB |
Output is correct |
67 |
Correct |
13 ms |
2156 KB |
Output is correct |
68 |
Correct |
5 ms |
2156 KB |
Output is correct |
69 |
Correct |
12 ms |
2156 KB |
Output is correct |
70 |
Correct |
11 ms |
2156 KB |
Output is correct |
71 |
Partially correct |
62 ms |
2156 KB |
Partially correct - number of queries: 5261 |
72 |
Correct |
11 ms |
2156 KB |
Output is correct |
73 |
Partially correct |
41 ms |
2156 KB |
Partially correct - number of queries: 5191 |
74 |
Partially correct |
46 ms |
2156 KB |
Partially correct - number of queries: 5221 |
75 |
Correct |
5 ms |
2156 KB |
Output is correct |
76 |
Correct |
22 ms |
2156 KB |
Output is correct |
77 |
Partially correct |
48 ms |
2156 KB |
Partially correct - number of queries: 5136 |
78 |
Correct |
9 ms |
2156 KB |
Output is correct |
79 |
Correct |
27 ms |
2156 KB |
Output is correct |
80 |
Partially correct |
65 ms |
2156 KB |
Partially correct - number of queries: 5119 |
81 |
Partially correct |
66 ms |
2156 KB |
Partially correct - number of queries: 5114 |
82 |
Partially correct |
71 ms |
2156 KB |
Partially correct - number of queries: 5065 |
83 |
Correct |
6 ms |
2156 KB |
Output is correct |
84 |
Correct |
46 ms |
2156 KB |
Output is correct |
85 |
Partially correct |
71 ms |
2156 KB |
Partially correct - number of queries: 5143 |
86 |
Runtime error |
46 ms |
3792 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
87 |
Halted |
0 ms |
0 KB |
- |