#include <bits/stdc++.h>
#include "prize.h"
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
unordered_map<int, pii> mp;
//vector<int> ask(int p) {
// cout << p << endl;
// int a, b; cin >> a >> b;
// return {a, b};
//}
pii query(int p) {
if(mp.find(p) != mp.end()) return mp[p];
vector<int> v = ask(p);
return mp[p] = {v[0], v[1]};
}
int find_best(int n) {
int mx = 0;
set<int> Yeee;
for(int i = 0; i < min(n, 50); i ++) {
int p = rand() % n;
pii r = query(p);
mx = max(mx, r.F + r.S);
}
cout << mx << endl;
vector<pair<int, pii> > OK;
for(int i = 0; i < n; i ++) {
pii p = query(i);
// cout << " QQ " << i << ' ' << p.F << ' ' << p.S << endl;
if(p.F + p.S == mx) {
int l = i + 1, r = n;
while(l != r) {
int m = l + r >> 1;
pii v = query(m);
if(v.F == p.F and v.S == p.S) {
i = m;
l = i + 1, r = n;
}
else {
r = m;
}
}
if(l < n) {
OK.push_back({l, query(l)});
// cout << "INS " << l << endl;
}
}
else {
OK.push_back({i, p});
}
}
// for(auto it: OK) cout << "OK " << it.F << endl;
pii ans = {1 << 30, -1};
// cout << OK.size() << endl;
for(auto it: OK) ans = min(ans, {it.S.F + it.S.S, it.F});
return ans.S;
}
//main () {
// cout << find_best(7);
//}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:34:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Token "1" doesn't correspond to pattern "[A-B]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
256 KB |
Token "1" doesn't correspond to pattern "[A-B]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |