#include "prize.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
map<int,vector<int> > m;
int c=0,k=0;
set<int> s;
vector<int> query(int x){
if(m.find(x)==m.end()){
m[x]=ask(x);
return m[x];
}
return m[x];
}
mt19937 rnd(43243214);
int find_best(int n) {
if(n<=5000){
for(int i=0;i<n;i++){
auto h=query(i);
if(h[0]==0 && h[1]==0){
return i;
}
}
}
queue<pair<int,int> > q2;
q2.push({-1,n});
int cr=0;;
while(q2.size() && cr<480){
auto h=q2.front();
q2.pop();
int x=(h.fs+h.sc)/2;
k=max(k,query(x)[0]+query(x)[1]);
q2.push({h.fs,x});
q2.push({x,h.sc});
cr++;
}
m[-1]={0,k};
m[n]={k,0};
queue<pair<int,int> > q;
q.push({-1,n});
while(q.size()){
auto h=q.front();
q.pop();
int cz=0;
for(auto it=s.lower_bound(h.fs);it!=s.end() && (*it)<h.sc;it++){
cz++;
}
if(query(h.fs)[0]==query(h.sc)[0]-cz){
continue;
}
int x=(h.fs+h.sc)/2;
int flag=0;
for(int i=x;i>h.fs;i--){
auto y=query(i);
if(y[0]+y[1]==k){
q.push({i,h.sc});
q.push({h.fs,i});
flag=1;
break;
}
else{
s.insert(i);
}
}
if(flag==0){
for(int i=x+1;i<h.sc;i++){
auto y=query(i);
if(y[0]+y[1]==k){
q.push({i,h.sc});
flag=1;
break;
}
else{
s.insert(i);
}
}
}
}
for(auto h:s){
if(query(h)[0]==0 && query(h)[1]==0){
return h;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
4 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
292 KB |
Output is correct |
4 |
Correct |
4 ms |
336 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
304 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
352 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
296 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
336 KB |
Output is correct |
11 |
Correct |
5 ms |
336 KB |
Output is correct |
12 |
Correct |
7 ms |
296 KB |
Output is correct |
13 |
Correct |
7 ms |
292 KB |
Output is correct |
14 |
Correct |
10 ms |
388 KB |
Output is correct |
15 |
Correct |
19 ms |
776 KB |
Output is correct |
16 |
Correct |
43 ms |
712 KB |
Output is correct |
17 |
Correct |
35 ms |
804 KB |
Output is correct |
18 |
Correct |
20 ms |
776 KB |
Output is correct |
19 |
Correct |
30 ms |
712 KB |
Output is correct |
20 |
Correct |
14 ms |
708 KB |
Output is correct |
21 |
Correct |
33 ms |
684 KB |
Output is correct |
22 |
Correct |
19 ms |
588 KB |
Output is correct |
23 |
Correct |
5 ms |
292 KB |
Output is correct |
24 |
Correct |
8 ms |
348 KB |
Output is correct |
25 |
Correct |
42 ms |
672 KB |
Output is correct |
26 |
Correct |
26 ms |
800 KB |
Output is correct |
27 |
Correct |
3 ms |
364 KB |
Output is correct |
28 |
Correct |
24 ms |
696 KB |
Output is correct |
29 |
Correct |
32 ms |
648 KB |
Output is correct |
30 |
Correct |
25 ms |
788 KB |
Output is correct |
31 |
Correct |
38 ms |
680 KB |
Output is correct |
32 |
Correct |
6 ms |
352 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
20 ms |
760 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
30 ms |
720 KB |
Output is correct |
37 |
Correct |
7 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
364 KB |
Output is correct |
39 |
Correct |
29 ms |
768 KB |
Output is correct |
40 |
Correct |
28 ms |
732 KB |
Output is correct |
41 |
Correct |
42 ms |
712 KB |
Output is correct |
42 |
Correct |
42 ms |
744 KB |
Output is correct |
43 |
Correct |
38 ms |
752 KB |
Output is correct |
44 |
Correct |
19 ms |
772 KB |
Output is correct |
45 |
Correct |
32 ms |
688 KB |
Output is correct |
46 |
Correct |
42 ms |
712 KB |
Output is correct |
47 |
Correct |
35 ms |
860 KB |
Output is correct |
48 |
Correct |
38 ms |
700 KB |
Output is correct |
49 |
Correct |
44 ms |
704 KB |
Output is correct |
50 |
Correct |
19 ms |
788 KB |
Output is correct |
51 |
Correct |
43 ms |
704 KB |
Output is correct |
52 |
Correct |
33 ms |
788 KB |
Output is correct |
53 |
Correct |
3 ms |
360 KB |
Output is correct |
54 |
Correct |
41 ms |
732 KB |
Output is correct |
55 |
Correct |
40 ms |
788 KB |
Output is correct |
56 |
Correct |
39 ms |
772 KB |
Output is correct |
57 |
Correct |
37 ms |
768 KB |
Output is correct |
58 |
Correct |
33 ms |
716 KB |
Output is correct |
59 |
Correct |
20 ms |
780 KB |
Output is correct |
60 |
Correct |
39 ms |
712 KB |
Output is correct |
61 |
Correct |
5 ms |
336 KB |
Output is correct |
62 |
Correct |
5 ms |
336 KB |
Output is correct |
63 |
Correct |
5 ms |
300 KB |
Output is correct |
64 |
Correct |
5 ms |
296 KB |
Output is correct |
65 |
Correct |
4 ms |
328 KB |
Output is correct |
66 |
Correct |
9 ms |
336 KB |
Output is correct |
67 |
Correct |
9 ms |
336 KB |
Output is correct |
68 |
Correct |
4 ms |
372 KB |
Output is correct |
69 |
Correct |
4 ms |
368 KB |
Output is correct |
70 |
Correct |
5 ms |
292 KB |
Output is correct |
71 |
Correct |
43 ms |
712 KB |
Output is correct |
72 |
Correct |
6 ms |
352 KB |
Output is correct |
73 |
Correct |
43 ms |
784 KB |
Output is correct |
74 |
Correct |
41 ms |
784 KB |
Output is correct |
75 |
Correct |
5 ms |
348 KB |
Output is correct |
76 |
Correct |
38 ms |
676 KB |
Output is correct |
77 |
Correct |
37 ms |
780 KB |
Output is correct |
78 |
Correct |
5 ms |
332 KB |
Output is correct |
79 |
Correct |
15 ms |
536 KB |
Output is correct |
80 |
Correct |
32 ms |
764 KB |
Output is correct |
81 |
Correct |
32 ms |
708 KB |
Output is correct |
82 |
Correct |
39 ms |
688 KB |
Output is correct |
83 |
Correct |
4 ms |
336 KB |
Output is correct |
84 |
Correct |
36 ms |
608 KB |
Output is correct |
85 |
Correct |
39 ms |
788 KB |
Output is correct |
86 |
Correct |
32 ms |
808 KB |
Output is correct |
87 |
Correct |
8 ms |
336 KB |
Output is correct |
88 |
Correct |
39 ms |
756 KB |
Output is correct |
89 |
Correct |
40 ms |
744 KB |
Output is correct |
90 |
Correct |
3 ms |
336 KB |
Output is correct |
91 |
Correct |
22 ms |
720 KB |
Output is correct |
92 |
Correct |
23 ms |
668 KB |
Output is correct |
93 |
Correct |
33 ms |
824 KB |
Output is correct |
94 |
Correct |
45 ms |
740 KB |
Output is correct |
95 |
Correct |
41 ms |
752 KB |
Output is correct |
96 |
Correct |
44 ms |
768 KB |
Output is correct |
97 |
Correct |
41 ms |
776 KB |
Output is correct |