#include "prize.h"
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
using namespace std;
int find_best(int n){
vector<vector<int>> tab(n);
auto zapytaj = [&](int i){
if(tab[i].empty()) tab[i] = ask(i);
return tab[i];
};
if(n <= 5000){
REP(i, n) if(zapytaj(i)[0]+zapytaj(i)[1] == 0) return i;
return -69;
}
int maks = 0;
REP(i, min(n, 500)){
int t = zapytaj(i)[0] + zapytaj(i)[1];
if(!t) return i;
maks = max(maks, t);
}
int wynik = -1;
function<void(int, int, int, int)> zwyciezaj = [&](int p, int k, int przed, int tutaj){
//~ printf("%d %d %d %d\n", p, k, przed, tutaj);
if(wynik>=0 || p>k || !tutaj) return;
int sr_org = (p+k)>>1;
int sr = sr_org;
vector<int> t = zapytaj(sr);
while(1){
if(t[0]+t[1] == 0) return void(wynik = sr);
if(t[0]+t[1] == maks) break;
--sr;
if(sr < p) break;
t = zapytaj(sr);
}
int lewo = sr>=p ? t[0]-przed : 0;
int roz = sr_org-sr;
zwyciezaj(p, sr-1, przed, lewo);
zwyciezaj(sr_org+1, k, przed+lewo+roz, tutaj-lewo-roz);
};
zwyciezaj(0, n-1, 0, maks);
return wynik;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5400 KB |
Output is correct |
2 |
Correct |
4 ms |
5396 KB |
Output is correct |
3 |
Correct |
4 ms |
5404 KB |
Output is correct |
4 |
Correct |
5 ms |
5400 KB |
Output is correct |
5 |
Correct |
5 ms |
5404 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
4 ms |
5656 KB |
Output is correct |
8 |
Correct |
4 ms |
5576 KB |
Output is correct |
9 |
Correct |
4 ms |
5408 KB |
Output is correct |
10 |
Correct |
4 ms |
5148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5156 KB |
Output is correct |
2 |
Correct |
4 ms |
5156 KB |
Output is correct |
3 |
Correct |
3 ms |
5404 KB |
Output is correct |
4 |
Correct |
5 ms |
5156 KB |
Output is correct |
5 |
Correct |
5 ms |
5664 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
3 ms |
5412 KB |
Output is correct |
8 |
Correct |
4 ms |
5404 KB |
Output is correct |
9 |
Correct |
4 ms |
5404 KB |
Output is correct |
10 |
Correct |
5 ms |
5160 KB |
Output is correct |
11 |
Correct |
5 ms |
5416 KB |
Output is correct |
12 |
Correct |
4 ms |
5160 KB |
Output is correct |
13 |
Correct |
8 ms |
5400 KB |
Output is correct |
14 |
Correct |
3 ms |
1200 KB |
Output is correct |
15 |
Correct |
6 ms |
5172 KB |
Output is correct |
16 |
Correct |
21 ms |
5728 KB |
Output is correct |
17 |
Correct |
3 ms |
5152 KB |
Output is correct |
18 |
Correct |
23 ms |
5960 KB |
Output is correct |
19 |
Correct |
4 ms |
5408 KB |
Output is correct |
20 |
Correct |
8 ms |
2972 KB |
Output is correct |
21 |
Correct |
11 ms |
5696 KB |
Output is correct |
22 |
Correct |
6 ms |
6180 KB |
Output is correct |
23 |
Correct |
4 ms |
5584 KB |
Output is correct |
24 |
Correct |
5 ms |
5152 KB |
Output is correct |
25 |
Correct |
13 ms |
6200 KB |
Output is correct |
26 |
Correct |
16 ms |
5704 KB |
Output is correct |
27 |
Correct |
4 ms |
5164 KB |
Output is correct |
28 |
Correct |
20 ms |
5980 KB |
Output is correct |
29 |
Correct |
19 ms |
5728 KB |
Output is correct |
30 |
Correct |
26 ms |
5764 KB |
Output is correct |
31 |
Correct |
4 ms |
5404 KB |
Output is correct |
32 |
Correct |
6 ms |
5660 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
10 ms |
5692 KB |
Output is correct |
35 |
Correct |
4 ms |
5660 KB |
Output is correct |
36 |
Correct |
7 ms |
5428 KB |
Output is correct |
37 |
Correct |
4 ms |
5404 KB |
Output is correct |
38 |
Correct |
4 ms |
5156 KB |
Output is correct |
39 |
Correct |
15 ms |
5452 KB |
Output is correct |
40 |
Correct |
21 ms |
6004 KB |
Output is correct |
41 |
Correct |
16 ms |
6196 KB |
Output is correct |
42 |
Correct |
17 ms |
5904 KB |
Output is correct |
43 |
Correct |
13 ms |
5688 KB |
Output is correct |
44 |
Correct |
12 ms |
5944 KB |
Output is correct |
45 |
Correct |
9 ms |
5436 KB |
Output is correct |
46 |
Correct |
3 ms |
5412 KB |
Output is correct |
47 |
Correct |
13 ms |
5924 KB |
Output is correct |
48 |
Correct |
22 ms |
5680 KB |
Output is correct |
49 |
Correct |
5 ms |
5396 KB |
Output is correct |
50 |
Correct |
29 ms |
5464 KB |
Output is correct |
51 |
Correct |
16 ms |
5680 KB |
Output is correct |
52 |
Correct |
4 ms |
5164 KB |
Output is correct |
53 |
Correct |
5 ms |
5404 KB |
Output is correct |
54 |
Correct |
17 ms |
5660 KB |
Output is correct |
55 |
Correct |
4 ms |
5408 KB |
Output is correct |
56 |
Correct |
26 ms |
5988 KB |
Output is correct |
57 |
Correct |
22 ms |
5464 KB |
Output is correct |
58 |
Correct |
23 ms |
5676 KB |
Output is correct |
59 |
Correct |
19 ms |
5688 KB |
Output is correct |
60 |
Correct |
12 ms |
5972 KB |
Output is correct |
61 |
Correct |
5 ms |
5400 KB |
Output is correct |
62 |
Correct |
4 ms |
5660 KB |
Output is correct |
63 |
Correct |
4 ms |
5404 KB |
Output is correct |
64 |
Correct |
5 ms |
5152 KB |
Output is correct |
65 |
Correct |
4 ms |
5408 KB |
Output is correct |
66 |
Correct |
7 ms |
6100 KB |
Output is correct |
67 |
Correct |
5 ms |
5408 KB |
Output is correct |
68 |
Correct |
3 ms |
5156 KB |
Output is correct |
69 |
Correct |
7 ms |
5668 KB |
Output is correct |
70 |
Correct |
4 ms |
5400 KB |
Output is correct |
71 |
Partially correct |
25 ms |
6284 KB |
Partially correct - number of queries: 5258 |
72 |
Correct |
6 ms |
5168 KB |
Output is correct |
73 |
Partially correct |
30 ms |
5720 KB |
Partially correct - number of queries: 5195 |
74 |
Partially correct |
30 ms |
5988 KB |
Partially correct - number of queries: 5222 |
75 |
Correct |
4 ms |
5168 KB |
Output is correct |
76 |
Correct |
20 ms |
5696 KB |
Output is correct |
77 |
Correct |
26 ms |
6172 KB |
Output is correct |
78 |
Correct |
6 ms |
5656 KB |
Output is correct |
79 |
Correct |
16 ms |
5720 KB |
Output is correct |
80 |
Correct |
25 ms |
6732 KB |
Output is correct |
81 |
Correct |
24 ms |
6184 KB |
Output is correct |
82 |
Correct |
30 ms |
5672 KB |
Output is correct |
83 |
Correct |
5 ms |
5656 KB |
Output is correct |
84 |
Correct |
22 ms |
6184 KB |
Output is correct |
85 |
Correct |
20 ms |
5792 KB |
Output is correct |
86 |
Correct |
5 ms |
5920 KB |
Output is correct |
87 |
Correct |
5 ms |
5656 KB |
Output is correct |
88 |
Correct |
4 ms |
5400 KB |
Output is correct |
89 |
Correct |
4 ms |
5404 KB |
Output is correct |
90 |
Correct |
5 ms |
5656 KB |
Output is correct |
91 |
Correct |
5 ms |
5404 KB |
Output is correct |
92 |
Correct |
3 ms |
5656 KB |
Output is correct |
93 |
Correct |
6 ms |
5908 KB |
Output is correct |
94 |
Correct |
5 ms |
5156 KB |
Output is correct |
95 |
Correct |
5 ms |
5412 KB |
Output is correct |
96 |
Correct |
5 ms |
5664 KB |
Output is correct |
97 |
Correct |
4 ms |
5404 KB |
Output is correct |