#include "bits/stdc++.h"
#include "prize.h"
//#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
int suf = -1;
vector<int> Cache={-1,-1};
map<int,vector<int>> dp;
vector<int> Ask(int i){
if(dp.count(i)) return dp[i];
return dp[i]=ask(i);
}
int ask_all(int l,int r){
for(int i=l;i<=r;i++){
vector<int> x = Ask(i);
if(x[0]+x[1]==0) return i;
if(x[1]==suf) Cache=x;
else suf--;
}
return -23;
}
int Learn(int l,int r){
if(l>r) return -1;
if(l==r){
auto u = Ask(l);
if(u[0]+u[1]==0) return l;
if(u[1]==suf) Cache=u;
else suf--;
return -1;
}
auto X = Ask(r);
if(X[0]+X[1]==0) return r;
if(X[1]==suf) return -1;
int mid = (l+r)/2;
auto u = Ask(mid);
if(u[0]+u[1]==0) return mid;
if(u[1]==suf) return Learn(mid+1,r);
int lf = Learn(l,mid-1);
if(lf!=-1) return lf;
if(u[1]==suf) Cache=u;
else suf--;
if(X[1]==suf) return -1;
return Learn(mid+1,r);
}
int find_best(int n){
if(n<=1000) return ask_all(0,n-1);
int art=0;
for(int i=0;i<=500;i++){
if(art==5) return Learn(i,n-1);
vector<int> x = Ask(i);
if(x[0]+x[1]==0) return i;
if(x[0]+x[1]>Cache[0]+Cache[1]) art++;
if(x[0]+x[1]>=Cache[0]+Cache[1]){
Cache=x;
suf=Cache[1];
}
else suf--;
}
return Learn(501,n-1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
336 KB |
Output is correct |
2 |
Correct |
9 ms |
336 KB |
Output is correct |
3 |
Correct |
9 ms |
448 KB |
Output is correct |
4 |
Correct |
8 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
9 ms |
336 KB |
Output is correct |
8 |
Correct |
9 ms |
336 KB |
Output is correct |
9 |
Correct |
8 ms |
336 KB |
Output is correct |
10 |
Correct |
9 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
496 KB |
Output is correct |
2 |
Correct |
8 ms |
592 KB |
Output is correct |
3 |
Correct |
9 ms |
492 KB |
Output is correct |
4 |
Correct |
9 ms |
592 KB |
Output is correct |
5 |
Correct |
10 ms |
584 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
10 ms |
336 KB |
Output is correct |
8 |
Correct |
9 ms |
336 KB |
Output is correct |
9 |
Correct |
10 ms |
336 KB |
Output is correct |
10 |
Correct |
10 ms |
336 KB |
Output is correct |
11 |
Correct |
15 ms |
480 KB |
Output is correct |
12 |
Correct |
9 ms |
336 KB |
Output is correct |
13 |
Correct |
20 ms |
548 KB |
Output is correct |
14 |
Correct |
15 ms |
592 KB |
Output is correct |
15 |
Correct |
21 ms |
540 KB |
Output is correct |
16 |
Partially correct |
107 ms |
1160 KB |
Partially correct - number of queries: 5557 |
17 |
Correct |
8 ms |
336 KB |
Output is correct |
18 |
Partially correct |
126 ms |
1400 KB |
Partially correct - number of queries: 6628 |
19 |
Correct |
8 ms |
592 KB |
Output is correct |
20 |
Correct |
29 ms |
584 KB |
Output is correct |
21 |
Correct |
46 ms |
840 KB |
Output is correct |
22 |
Correct |
16 ms |
336 KB |
Output is correct |
23 |
Correct |
9 ms |
592 KB |
Output is correct |
24 |
Correct |
9 ms |
336 KB |
Output is correct |
25 |
Correct |
56 ms |
852 KB |
Output is correct |
26 |
Correct |
62 ms |
840 KB |
Output is correct |
27 |
Correct |
10 ms |
336 KB |
Output is correct |
28 |
Partially correct |
106 ms |
1468 KB |
Partially correct - number of queries: 5791 |
29 |
Correct |
94 ms |
1160 KB |
Output is correct |
30 |
Partially correct |
118 ms |
1248 KB |
Partially correct - number of queries: 6509 |
31 |
Correct |
8 ms |
336 KB |
Output is correct |
32 |
Correct |
16 ms |
584 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
43 ms |
872 KB |
Output is correct |
35 |
Correct |
13 ms |
584 KB |
Output is correct |
36 |
Correct |
28 ms |
704 KB |
Output is correct |
37 |
Correct |
11 ms |
336 KB |
Output is correct |
38 |
Correct |
8 ms |
336 KB |
Output is correct |
39 |
Correct |
57 ms |
848 KB |
Output is correct |
40 |
Partially correct |
98 ms |
940 KB |
Partially correct - number of queries: 5755 |
41 |
Correct |
65 ms |
1036 KB |
Output is correct |
42 |
Correct |
66 ms |
848 KB |
Output is correct |
43 |
Correct |
66 ms |
824 KB |
Output is correct |
44 |
Correct |
40 ms |
1176 KB |
Output is correct |
45 |
Correct |
34 ms |
820 KB |
Output is correct |
46 |
Correct |
8 ms |
464 KB |
Output is correct |
47 |
Correct |
57 ms |
716 KB |
Output is correct |
48 |
Correct |
83 ms |
1132 KB |
Output is correct |
49 |
Correct |
15 ms |
336 KB |
Output is correct |
50 |
Partially correct |
122 ms |
1272 KB |
Partially correct - number of queries: 6618 |
51 |
Correct |
51 ms |
584 KB |
Output is correct |
52 |
Correct |
11 ms |
584 KB |
Output is correct |
53 |
Correct |
12 ms |
336 KB |
Output is correct |
54 |
Correct |
50 ms |
584 KB |
Output is correct |
55 |
Correct |
7 ms |
336 KB |
Output is correct |
56 |
Partially correct |
139 ms |
1280 KB |
Partially correct - number of queries: 6656 |
57 |
Correct |
84 ms |
1016 KB |
Output is correct |
58 |
Correct |
97 ms |
908 KB |
Output is correct |
59 |
Correct |
69 ms |
1076 KB |
Output is correct |
60 |
Correct |
64 ms |
884 KB |
Output is correct |
61 |
Correct |
10 ms |
460 KB |
Output is correct |
62 |
Correct |
9 ms |
336 KB |
Output is correct |
63 |
Correct |
9 ms |
336 KB |
Output is correct |
64 |
Correct |
10 ms |
336 KB |
Output is correct |
65 |
Correct |
9 ms |
592 KB |
Output is correct |
66 |
Correct |
19 ms |
336 KB |
Output is correct |
67 |
Correct |
9 ms |
336 KB |
Output is correct |
68 |
Correct |
8 ms |
592 KB |
Output is correct |
69 |
Correct |
21 ms |
592 KB |
Output is correct |
70 |
Correct |
9 ms |
336 KB |
Output is correct |
71 |
Partially correct |
128 ms |
1760 KB |
Partially correct - number of queries: 6536 |
72 |
Correct |
21 ms |
336 KB |
Output is correct |
73 |
Partially correct |
130 ms |
1124 KB |
Partially correct - number of queries: 6459 |
74 |
Partially correct |
125 ms |
1644 KB |
Partially correct - number of queries: 6492 |
75 |
Correct |
9 ms |
604 KB |
Output is correct |
76 |
Partially correct |
122 ms |
1300 KB |
Partially correct - number of queries: 5744 |
77 |
Partially correct |
132 ms |
1260 KB |
Partially correct - number of queries: 6200 |
78 |
Correct |
19 ms |
336 KB |
Output is correct |
79 |
Correct |
68 ms |
1128 KB |
Output is correct |
80 |
Partially correct |
120 ms |
1204 KB |
Partially correct - number of queries: 6182 |
81 |
Partially correct |
132 ms |
1420 KB |
Partially correct - number of queries: 6242 |
82 |
Partially correct |
112 ms |
1220 KB |
Partially correct - number of queries: 6074 |
83 |
Correct |
12 ms |
460 KB |
Output is correct |
84 |
Partially correct |
114 ms |
1176 KB |
Partially correct - number of queries: 5229 |
85 |
Partially correct |
107 ms |
1096 KB |
Partially correct - number of queries: 6219 |
86 |
Correct |
9 ms |
336 KB |
Output is correct |
87 |
Correct |
9 ms |
336 KB |
Output is correct |
88 |
Correct |
10 ms |
336 KB |
Output is correct |
89 |
Correct |
8 ms |
592 KB |
Output is correct |
90 |
Correct |
9 ms |
464 KB |
Output is correct |
91 |
Correct |
7 ms |
336 KB |
Output is correct |
92 |
Correct |
9 ms |
336 KB |
Output is correct |
93 |
Correct |
16 ms |
520 KB |
Output is correct |
94 |
Correct |
16 ms |
592 KB |
Output is correct |
95 |
Correct |
15 ms |
592 KB |
Output is correct |
96 |
Correct |
14 ms |
724 KB |
Output is correct |
97 |
Correct |
8 ms |
336 KB |
Output is correct |