This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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};
//}
int cnt = 0;
pii query(int p) {
if(mp.find(p) != mp.end()) return mp[p];
cnt ++;
assert(cnt < 10000);
vector<int> v = ask(p);
return mp[p] = {v[0], v[1]};
}
int find_best(int n) {
srand(time(0));
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);
}
vector<pair<int, pii> > OK;
for(int i = 0; i < n; i ++) {
pii p = query(i);
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)});
}
i = l;
}
else {
OK.push_back({i, p});
}
}
pii ans = {1 << 30, -1};
for(auto it: OK) ans = min(ans, {it.S.F + it.S.S, it.F});
assert(OK.size());
return ans.S;
}
//main () {
// cout << find_best(7);
//}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:36:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |