#include "prize.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 200013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N;
pii dp[MAXN];
ordered_set<int> cand;
int ans = -1, rec = 0;
pii query(int idx)
{
if (dp[idx] != MP(-1, -1)) return dp[idx];
vi tmp = ask(idx);
dp[idx] = {tmp[0], tmp[1]};
if (dp[idx] == MP(0, 0)) ans = idx;
return dp[idx];
}
int find_best(int n)
{
// return 0;
N = n;
if (N == 1) return 0;
FOR(i, 0, N) dp[i] = {-1, -1};
int pos = -1;
for (int i = 0; i < N && i <= 480; i++)
{
pii p = query(i); if (ans != -1) return ans;
if (pos == -1 || p.fi + p.se > dp[pos].fi + dp[pos].se) pos = i;
}
rec = dp[pos].fi + dp[pos].se;
FOR(i, pos, N) cand.insert(i);
//find the last guy that still matches it.
// for (int x : cand)
// {
// cerr << x << ' ';
// }
// cerr << endl;
while(true)
{
pii p = query(pos);
//find the last guy that's == pos
int i = 0;
for (;; i++)
{
if ((1 << i) >= SZ(cand)) break;
int cur = *cand.find_by_order((1 << i));
pii q = query(cur); if (ans != -1) return ans;
// cerr << cur << ' ' << q.fi << ' ' << q.se << endl;
if (p != q) break;
//find the block that's >= pos
}
int lo = 0, hi = min(SZ(cand), (1 << i)) - 1;
// cerr << lo << ' ' << hi << endl;
while(hi > lo)
{
int mid = (hi + lo + 1) >> 1;
int cur = *cand.find_by_order(mid);
pii q = query(cur); if (ans != -1) return ans;
if (p != q) hi = mid - 1;
else lo = mid;
}
pos = *cand.find_by_order(lo) + 1;
FOR(i, 0, lo + 1)
{
// cerr << "ERASE " << *cand.begin() << endl;
cand.erase(cand.begin());
}
while(true)
{
pii p = query(pos); if (ans != -1) return ans;
if (p.fi + p.se == rec) break;
cand.erase(cand.begin()); pos++;
}
}
//pos is an example of the least worth guy.
//so each time you just want to find an example of any guy worth more than it.
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
11292 KB |
Output is correct |
2 |
Correct |
148 ms |
11236 KB |
Output is correct |
3 |
Correct |
147 ms |
11236 KB |
Output is correct |
4 |
Correct |
147 ms |
11156 KB |
Output is correct |
5 |
Correct |
146 ms |
11256 KB |
Output is correct |
6 |
Correct |
3 ms |
1848 KB |
Output is correct |
7 |
Correct |
144 ms |
11324 KB |
Output is correct |
8 |
Correct |
144 ms |
11256 KB |
Output is correct |
9 |
Correct |
147 ms |
11320 KB |
Output is correct |
10 |
Correct |
149 ms |
11180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
11204 KB |
Output is correct |
2 |
Correct |
146 ms |
11240 KB |
Output is correct |
3 |
Correct |
147 ms |
11284 KB |
Output is correct |
4 |
Correct |
144 ms |
11228 KB |
Output is correct |
5 |
Correct |
144 ms |
11220 KB |
Output is correct |
6 |
Correct |
3 ms |
1928 KB |
Output is correct |
7 |
Correct |
149 ms |
11268 KB |
Output is correct |
8 |
Correct |
147 ms |
11288 KB |
Output is correct |
9 |
Correct |
148 ms |
11316 KB |
Output is correct |
10 |
Correct |
147 ms |
11176 KB |
Output is correct |
11 |
Correct |
161 ms |
11288 KB |
Output is correct |
12 |
Correct |
147 ms |
11256 KB |
Output is correct |
13 |
Correct |
179 ms |
11224 KB |
Output is correct |
14 |
Correct |
19 ms |
1400 KB |
Output is correct |
15 |
Correct |
169 ms |
11256 KB |
Output is correct |
16 |
Partially correct |
256 ms |
11184 KB |
Partially correct - number of queries: 7257 |
17 |
Correct |
10 ms |
1940 KB |
Output is correct |
18 |
Partially correct |
271 ms |
11240 KB |
Partially correct - number of queries: 8669 |
19 |
Correct |
8 ms |
1784 KB |
Output is correct |
20 |
Correct |
97 ms |
5772 KB |
Output is correct |
21 |
Correct |
190 ms |
11256 KB |
Output is correct |
22 |
Correct |
159 ms |
11320 KB |
Output is correct |
23 |
Correct |
143 ms |
11204 KB |
Output is correct |
24 |
Correct |
145 ms |
11180 KB |
Output is correct |
25 |
Correct |
208 ms |
11332 KB |
Output is correct |
26 |
Correct |
192 ms |
11232 KB |
Output is correct |
27 |
Correct |
157 ms |
11228 KB |
Output is correct |
28 |
Partially correct |
246 ms |
11196 KB |
Partially correct - number of queries: 7767 |
29 |
Partially correct |
229 ms |
11256 KB |
Partially correct - number of queries: 6155 |
30 |
Partially correct |
261 ms |
11228 KB |
Partially correct - number of queries: 8521 |
31 |
Correct |
7 ms |
1784 KB |
Output is correct |
32 |
Correct |
174 ms |
11220 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
186 ms |
11256 KB |
Output is correct |
35 |
Correct |
167 ms |
11184 KB |
Output is correct |
36 |
Correct |
171 ms |
11224 KB |
Output is correct |
37 |
Correct |
154 ms |
11244 KB |
Output is correct |
38 |
Correct |
147 ms |
11256 KB |
Output is correct |
39 |
Correct |
185 ms |
11256 KB |
Output is correct |
40 |
Partially correct |
262 ms |
11384 KB |
Partially correct - number of queries: 7424 |
41 |
Partially correct |
219 ms |
11288 KB |
Partially correct - number of queries: 5299 |
42 |
Partially correct |
219 ms |
11224 KB |
Partially correct - number of queries: 5299 |
43 |
Partially correct |
209 ms |
11336 KB |
Partially correct - number of queries: 5052 |
44 |
Correct |
178 ms |
11256 KB |
Output is correct |
45 |
Correct |
184 ms |
11180 KB |
Output is correct |
46 |
Correct |
6 ms |
1784 KB |
Output is correct |
47 |
Correct |
179 ms |
11224 KB |
Output is correct |
48 |
Partially correct |
232 ms |
11192 KB |
Partially correct - number of queries: 6296 |
49 |
Correct |
152 ms |
11228 KB |
Output is correct |
50 |
Partially correct |
261 ms |
11220 KB |
Partially correct - number of queries: 8689 |
51 |
Correct |
191 ms |
11160 KB |
Output is correct |
52 |
Correct |
147 ms |
11248 KB |
Output is correct |
53 |
Correct |
174 ms |
11152 KB |
Output is correct |
54 |
Correct |
186 ms |
11232 KB |
Output is correct |
55 |
Correct |
6 ms |
1852 KB |
Output is correct |
56 |
Partially correct |
251 ms |
11196 KB |
Partially correct - number of queries: 8675 |
57 |
Partially correct |
229 ms |
11212 KB |
Partially correct - number of queries: 6281 |
58 |
Partially correct |
225 ms |
11256 KB |
Partially correct - number of queries: 6407 |
59 |
Partially correct |
207 ms |
11292 KB |
Partially correct - number of queries: 5299 |
60 |
Correct |
206 ms |
11288 KB |
Output is correct |
61 |
Correct |
170 ms |
11336 KB |
Output is correct |
62 |
Correct |
144 ms |
11288 KB |
Output is correct |
63 |
Correct |
170 ms |
11256 KB |
Output is correct |
64 |
Correct |
162 ms |
11256 KB |
Output is correct |
65 |
Correct |
174 ms |
11196 KB |
Output is correct |
66 |
Correct |
177 ms |
11316 KB |
Output is correct |
67 |
Correct |
146 ms |
11244 KB |
Output is correct |
68 |
Correct |
9 ms |
1912 KB |
Output is correct |
69 |
Correct |
185 ms |
11196 KB |
Output is correct |
70 |
Correct |
145 ms |
11256 KB |
Output is correct |
71 |
Partially correct |
262 ms |
11188 KB |
Partially correct - number of queries: 8635 |
72 |
Correct |
184 ms |
11276 KB |
Output is correct |
73 |
Partially correct |
254 ms |
11256 KB |
Partially correct - number of queries: 8539 |
74 |
Partially correct |
217 ms |
11288 KB |
Partially correct - number of queries: 8581 |
75 |
Correct |
174 ms |
11352 KB |
Output is correct |
76 |
Partially correct |
209 ms |
11256 KB |
Partially correct - number of queries: 7632 |
77 |
Partially correct |
250 ms |
11304 KB |
Partially correct - number of queries: 8713 |
78 |
Correct |
182 ms |
11256 KB |
Output is correct |
79 |
Correct |
212 ms |
11220 KB |
Output is correct |
80 |
Partially correct |
258 ms |
11196 KB |
Partially correct - number of queries: 8691 |
81 |
Partially correct |
258 ms |
11244 KB |
Partially correct - number of queries: 8687 |
82 |
Partially correct |
264 ms |
11256 KB |
Partially correct - number of queries: 8607 |
83 |
Correct |
175 ms |
11304 KB |
Output is correct |
84 |
Partially correct |
250 ms |
11212 KB |
Partially correct - number of queries: 7373 |
85 |
Partially correct |
253 ms |
11308 KB |
Partially correct - number of queries: 8637 |
86 |
Correct |
145 ms |
11224 KB |
Output is correct |
87 |
Correct |
144 ms |
11348 KB |
Output is correct |
88 |
Correct |
144 ms |
11180 KB |
Output is correct |
89 |
Correct |
148 ms |
11232 KB |
Output is correct |
90 |
Correct |
162 ms |
11232 KB |
Output is correct |
91 |
Correct |
144 ms |
11220 KB |
Output is correct |
92 |
Correct |
151 ms |
11276 KB |
Output is correct |
93 |
Correct |
178 ms |
11172 KB |
Output is correct |
94 |
Correct |
179 ms |
11232 KB |
Output is correct |
95 |
Correct |
182 ms |
11136 KB |
Output is correct |
96 |
Correct |
178 ms |
11304 KB |
Output is correct |
97 |
Correct |
148 ms |
11268 KB |
Output is correct |