#include "prize.h"
#include <bits/stdc++.h>
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
map<ll, vector<ll>> cache;
vector<ll> query(int n){
if (cache.count(n)) return cache[n];
else return cache[n] = ask(n);
}
int find_best(int n) {
cache.clear();
vector<ll> stuff(n);
FOR(i,0,n) stuff[i] = i;
ll maxi = -1;
FOR(i,0,min(500, n)){
vector<ll> sus = query(i);
maxi = max(maxi, sus[0]+sus[1]);
}
vector<ll> found;
ll ans = -1;
while (ans == -1){
ll lo = 0;
ll hi = stuff.size()-1;
bool skip = false;
while (lo < hi){
ll mid = (lo+hi)/2;
FOR(i, max(lo, mid-100), min(hi, mid+100)){
if (cache.count(i)){
mid = i;
break;
}
}
vector<ll> sus = query(stuff[mid]);
if (sus[0] + sus[1] < maxi){
if (sus[0]+sus[1]==0) return stuff[mid];
found.push_back(stuff[mid]);
stuff.erase(stuff.begin()+mid);
skip = true;
break;
}else{
sort(found.begin(), found.end());
ll idk = upper_bound(found.begin(), found.end(), stuff[mid]) - found.begin();
if (idk < sus[0]){
hi = mid;
}else{
lo = mid+1;
}
}
}
if (skip) continue;
vector<ll> sus = query(stuff[lo]);
if (sus[0]+sus[1] == maxi) break;
if (sus[0]+sus[1]==0) return stuff[lo];
found.push_back(stuff[lo]);
stuff.erase(stuff.begin()+lo);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1112 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
3 ms |
1268 KB |
Output is correct |
4 |
Correct |
3 ms |
1112 KB |
Output is correct |
5 |
Correct |
2 ms |
1192 KB |
Output is correct |
6 |
Correct |
3 ms |
1220 KB |
Output is correct |
7 |
Correct |
2 ms |
1196 KB |
Output is correct |
8 |
Correct |
2 ms |
1188 KB |
Output is correct |
9 |
Correct |
3 ms |
1240 KB |
Output is correct |
10 |
Correct |
2 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1448 KB |
Output is correct |
2 |
Correct |
3 ms |
1112 KB |
Output is correct |
3 |
Correct |
3 ms |
1252 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
3 ms |
1204 KB |
Output is correct |
6 |
Correct |
3 ms |
1200 KB |
Output is correct |
7 |
Correct |
2 ms |
1200 KB |
Output is correct |
8 |
Correct |
2 ms |
1260 KB |
Output is correct |
9 |
Correct |
3 ms |
1248 KB |
Output is correct |
10 |
Correct |
3 ms |
1368 KB |
Output is correct |
11 |
Correct |
4 ms |
1304 KB |
Output is correct |
12 |
Correct |
3 ms |
1364 KB |
Output is correct |
13 |
Correct |
7 ms |
1452 KB |
Output is correct |
14 |
Correct |
5 ms |
524 KB |
Output is correct |
15 |
Correct |
12 ms |
1284 KB |
Output is correct |
16 |
Partially correct |
51 ms |
1964 KB |
Partially correct - number of queries: 6890 |
17 |
Correct |
3 ms |
1224 KB |
Output is correct |
18 |
Partially correct |
64 ms |
2108 KB |
Partially correct - number of queries: 8245 |
19 |
Correct |
3 ms |
1264 KB |
Output is correct |
20 |
Correct |
15 ms |
1068 KB |
Output is correct |
21 |
Correct |
25 ms |
1488 KB |
Output is correct |
22 |
Correct |
9 ms |
1280 KB |
Output is correct |
23 |
Correct |
4 ms |
1260 KB |
Output is correct |
24 |
Correct |
4 ms |
1524 KB |
Output is correct |
25 |
Correct |
39 ms |
1680 KB |
Output is correct |
26 |
Correct |
33 ms |
1740 KB |
Output is correct |
27 |
Correct |
4 ms |
1112 KB |
Output is correct |
28 |
Partially correct |
60 ms |
1808 KB |
Partially correct - number of queries: 7152 |
29 |
Partially correct |
51 ms |
1616 KB |
Partially correct - number of queries: 5658 |
30 |
Partially correct |
72 ms |
2080 KB |
Partially correct - number of queries: 8195 |
31 |
Correct |
3 ms |
1108 KB |
Output is correct |
32 |
Correct |
8 ms |
1336 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
22 ms |
1780 KB |
Output is correct |
35 |
Correct |
5 ms |
1252 KB |
Output is correct |
36 |
Correct |
22 ms |
1668 KB |
Output is correct |
37 |
Correct |
4 ms |
1200 KB |
Output is correct |
38 |
Correct |
3 ms |
1112 KB |
Output is correct |
39 |
Correct |
36 ms |
1428 KB |
Output is correct |
40 |
Partially correct |
49 ms |
1660 KB |
Partially correct - number of queries: 6382 |
41 |
Partially correct |
40 ms |
1868 KB |
Partially correct - number of queries: 5100 |
42 |
Partially correct |
36 ms |
1912 KB |
Partially correct - number of queries: 5100 |
43 |
Correct |
30 ms |
1528 KB |
Output is correct |
44 |
Correct |
30 ms |
1612 KB |
Output is correct |
45 |
Correct |
29 ms |
1624 KB |
Output is correct |
46 |
Correct |
2 ms |
1108 KB |
Output is correct |
47 |
Correct |
28 ms |
1624 KB |
Output is correct |
48 |
Partially correct |
46 ms |
1964 KB |
Partially correct - number of queries: 6181 |
49 |
Correct |
10 ms |
1372 KB |
Output is correct |
50 |
Partially correct |
83 ms |
2188 KB |
Partially correct - number of queries: 7910 |
51 |
Correct |
22 ms |
1616 KB |
Output is correct |
52 |
Correct |
4 ms |
1112 KB |
Output is correct |
53 |
Correct |
4 ms |
1112 KB |
Output is correct |
54 |
Correct |
25 ms |
1740 KB |
Output is correct |
55 |
Correct |
3 ms |
1364 KB |
Output is correct |
56 |
Partially correct |
58 ms |
1916 KB |
Partially correct - number of queries: 8036 |
57 |
Partially correct |
45 ms |
1776 KB |
Partially correct - number of queries: 5889 |
58 |
Partially correct |
42 ms |
2128 KB |
Partially correct - number of queries: 6297 |
59 |
Partially correct |
45 ms |
1584 KB |
Partially correct - number of queries: 5084 |
60 |
Correct |
33 ms |
1616 KB |
Output is correct |
61 |
Correct |
4 ms |
1316 KB |
Output is correct |
62 |
Correct |
2 ms |
1112 KB |
Output is correct |
63 |
Correct |
6 ms |
1296 KB |
Output is correct |
64 |
Correct |
4 ms |
1112 KB |
Output is correct |
65 |
Correct |
3 ms |
1112 KB |
Output is correct |
66 |
Correct |
11 ms |
1112 KB |
Output is correct |
67 |
Correct |
19 ms |
1112 KB |
Output is correct |
68 |
Correct |
14 ms |
1368 KB |
Output is correct |
69 |
Correct |
10 ms |
1368 KB |
Output is correct |
70 |
Correct |
10 ms |
1112 KB |
Output is correct |
71 |
Incorrect |
84 ms |
2336 KB |
Incorrect |
72 |
Halted |
0 ms |
0 KB |
- |