#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> lcache;
vector<int> rcache;
int n;
pair<int,int> askmap(int i){
//cout<<"askmap "<<i<<endl;
if (i>=n){
return {1e9,1e9};
}
assert(i<n);
if (lcache[i]==-1){
vector<int> res = ask(i);
lcache[i] = res[0];
rcache[i] = res[1];
}
return {lcache[i],rcache[i]};
}
int asksum(int i){
auto p = askmap(i);
return p.first+p.second;
}
int lsum = 0;
int dnc(int s, int e, int numexp, int prefexp, int suffexp){
// numexp expensive things in range s->e
//cout<<s<<' '<<e<<' '<<numexp<<' '<<prefexp<<' '<<suffexp<<endl;
if (e-s+1==numexp){
for (int i = s; i<=e; i++){
if (asksum(i)==0){return i;}
}
return -1;
}
if (numexp==0){
return -1;
}
// there is at least one lollipop
int m = (s+e)/2;
for (int i = m; i>=s; i--){
if (asksum(i)==lsum){
auto m = askmap(i);
int lval = m.first;
int rval = m.second;
int dl = dnc(s,i-1,lval-prefexp, prefexp, rval);
if (dl!=-1){return dl;}
int dr = dnc(i+1,e,rval-suffexp, lval, suffexp);
if (dr!=-1){return dr;}
return -1;
} else if (asksum(i)==0){
return i;
}
}
for (int i = m+1; i<=e; i++){
if (asksum(i)==lsum){
auto m = askmap(i);
int lval = m.first;
int rval = m.second;
//int dl = dnc(s,i-1,lval-prefexp, prefexp, rval);
//if (dl!=-1){return dl;}
int dr = dnc(i+1,e,rval-suffexp, lval, suffexp);
if (dr!=-1){return dr;}
return -1;
} else if (asksum(i)==0){
return i;
}
}
assert(1==0);
}
int find_best(int N) {
n=N;
lcache.resize(n,-1);
rcache.resize(n,-1);
if (n<=500){
for (int i = 0; i < n; i++) {
if(asksum(i) == 0){
return i;
}
}
assert(1==0);
}
int m = (n-1)/2;
for (int i = m-236; i<m+236; i++){
int res = asksum(i);
if (res==0){return i;}
lsum = max(res,lsum);
}
return dnc(0,n-1,lsum,0,0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1920 KB |
Output is correct |
2 |
Correct |
6 ms |
1920 KB |
Output is correct |
3 |
Correct |
5 ms |
1920 KB |
Output is correct |
4 |
Correct |
7 ms |
1920 KB |
Output is correct |
5 |
Correct |
4 ms |
1920 KB |
Output is correct |
6 |
Correct |
7 ms |
1952 KB |
Output is correct |
7 |
Correct |
4 ms |
1920 KB |
Output is correct |
8 |
Correct |
3 ms |
1920 KB |
Output is correct |
9 |
Correct |
4 ms |
1920 KB |
Output is correct |
10 |
Correct |
6 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1920 KB |
Output is correct |
2 |
Correct |
6 ms |
1920 KB |
Output is correct |
3 |
Correct |
5 ms |
1920 KB |
Output is correct |
4 |
Correct |
5 ms |
1920 KB |
Output is correct |
5 |
Correct |
3 ms |
1912 KB |
Output is correct |
6 |
Correct |
4 ms |
1920 KB |
Output is correct |
7 |
Correct |
4 ms |
1912 KB |
Output is correct |
8 |
Correct |
4 ms |
1920 KB |
Output is correct |
9 |
Correct |
3 ms |
1920 KB |
Output is correct |
10 |
Correct |
7 ms |
1920 KB |
Output is correct |
11 |
Correct |
8 ms |
2040 KB |
Output is correct |
12 |
Correct |
4 ms |
1920 KB |
Output is correct |
13 |
Correct |
12 ms |
1920 KB |
Output is correct |
14 |
Correct |
7 ms |
512 KB |
Output is correct |
15 |
Correct |
10 ms |
1912 KB |
Output is correct |
16 |
Correct |
36 ms |
2040 KB |
Output is correct |
17 |
Correct |
6 ms |
1920 KB |
Output is correct |
18 |
Partially correct |
44 ms |
1920 KB |
Partially correct - number of queries: 5223 |
19 |
Correct |
7 ms |
1920 KB |
Output is correct |
20 |
Correct |
16 ms |
1152 KB |
Output is correct |
21 |
Correct |
22 ms |
1920 KB |
Output is correct |
22 |
Correct |
6 ms |
1912 KB |
Output is correct |
23 |
Correct |
5 ms |
1920 KB |
Output is correct |
24 |
Correct |
6 ms |
2048 KB |
Output is correct |
25 |
Correct |
29 ms |
2040 KB |
Output is correct |
26 |
Correct |
23 ms |
1920 KB |
Output is correct |
27 |
Correct |
7 ms |
1920 KB |
Output is correct |
28 |
Correct |
45 ms |
1920 KB |
Output is correct |
29 |
Correct |
37 ms |
1912 KB |
Output is correct |
30 |
Partially correct |
45 ms |
1920 KB |
Partially correct - number of queries: 5191 |
31 |
Correct |
4 ms |
1912 KB |
Output is correct |
32 |
Correct |
9 ms |
1920 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
19 ms |
1912 KB |
Output is correct |
35 |
Correct |
10 ms |
1920 KB |
Output is correct |
36 |
Correct |
10 ms |
1920 KB |
Output is correct |
37 |
Correct |
6 ms |
1920 KB |
Output is correct |
38 |
Correct |
4 ms |
2032 KB |
Output is correct |
39 |
Correct |
21 ms |
1912 KB |
Output is correct |
40 |
Correct |
25 ms |
1900 KB |
Output is correct |
41 |
Correct |
18 ms |
1920 KB |
Output is correct |
42 |
Correct |
28 ms |
1980 KB |
Output is correct |
43 |
Correct |
32 ms |
1948 KB |
Output is correct |
44 |
Correct |
23 ms |
1920 KB |
Output is correct |
45 |
Correct |
25 ms |
1920 KB |
Output is correct |
46 |
Correct |
4 ms |
1920 KB |
Output is correct |
47 |
Correct |
14 ms |
1980 KB |
Output is correct |
48 |
Correct |
31 ms |
1920 KB |
Output is correct |
49 |
Correct |
11 ms |
2040 KB |
Output is correct |
50 |
Partially correct |
55 ms |
1920 KB |
Partially correct - number of queries: 5229 |
51 |
Correct |
21 ms |
1920 KB |
Output is correct |
52 |
Correct |
7 ms |
1912 KB |
Output is correct |
53 |
Correct |
8 ms |
1920 KB |
Output is correct |
54 |
Correct |
30 ms |
1912 KB |
Output is correct |
55 |
Correct |
8 ms |
1920 KB |
Output is correct |
56 |
Partially correct |
64 ms |
1920 KB |
Partially correct - number of queries: 5228 |
57 |
Correct |
35 ms |
1912 KB |
Output is correct |
58 |
Correct |
44 ms |
1920 KB |
Output is correct |
59 |
Correct |
29 ms |
1912 KB |
Output is correct |
60 |
Correct |
23 ms |
1912 KB |
Output is correct |
61 |
Correct |
9 ms |
1912 KB |
Output is correct |
62 |
Correct |
6 ms |
1952 KB |
Output is correct |
63 |
Correct |
6 ms |
1920 KB |
Output is correct |
64 |
Correct |
9 ms |
1920 KB |
Output is correct |
65 |
Correct |
9 ms |
1920 KB |
Output is correct |
66 |
Correct |
7 ms |
1892 KB |
Output is correct |
67 |
Correct |
8 ms |
1920 KB |
Output is correct |
68 |
Correct |
10 ms |
1920 KB |
Output is correct |
69 |
Correct |
10 ms |
1984 KB |
Output is correct |
70 |
Correct |
11 ms |
1896 KB |
Output is correct |
71 |
Partially correct |
60 ms |
2040 KB |
Partially correct - number of queries: 5230 |
72 |
Correct |
14 ms |
1920 KB |
Output is correct |
73 |
Partially correct |
40 ms |
1920 KB |
Partially correct - number of queries: 5167 |
74 |
Partially correct |
56 ms |
1952 KB |
Partially correct - number of queries: 5194 |
75 |
Correct |
9 ms |
1920 KB |
Output is correct |
76 |
Correct |
38 ms |
1920 KB |
Output is correct |
77 |
Partially correct |
87 ms |
1920 KB |
Partially correct - number of queries: 5352 |
78 |
Correct |
16 ms |
2040 KB |
Output is correct |
79 |
Correct |
30 ms |
1948 KB |
Output is correct |
80 |
Partially correct |
59 ms |
1952 KB |
Partially correct - number of queries: 5323 |
81 |
Partially correct |
53 ms |
1920 KB |
Partially correct - number of queries: 5343 |
82 |
Partially correct |
47 ms |
1920 KB |
Partially correct - number of queries: 5256 |
83 |
Correct |
8 ms |
1920 KB |
Output is correct |
84 |
Correct |
47 ms |
1948 KB |
Output is correct |
85 |
Partially correct |
48 ms |
1948 KB |
Partially correct - number of queries: 5321 |
86 |
Correct |
11 ms |
1920 KB |
Output is correct |
87 |
Correct |
7 ms |
1952 KB |
Output is correct |
88 |
Correct |
9 ms |
1920 KB |
Output is correct |
89 |
Correct |
11 ms |
1920 KB |
Output is correct |
90 |
Correct |
7 ms |
1920 KB |
Output is correct |
91 |
Correct |
8 ms |
1920 KB |
Output is correct |
92 |
Correct |
10 ms |
1920 KB |
Output is correct |
93 |
Correct |
11 ms |
1952 KB |
Output is correct |
94 |
Correct |
10 ms |
1920 KB |
Output is correct |
95 |
Correct |
9 ms |
1920 KB |
Output is correct |
96 |
Correct |
9 ms |
1920 KB |
Output is correct |
97 |
Correct |
6 ms |
1920 KB |
Output is correct |