Submission #102309

# Submission time Handle Problem Language Result Execution time Memory
102309 2019-03-24T09:37:20 Z bert30702 The Big Prize (IOI17_prize) C++17
0 / 100
3 ms 412 KB
#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;
	set<int> s; s.insert(n);
	for(int i = 0; i < n; i ++) {
		pii p = query(i);
		if(p.F + p.S == mx) {
			while(s.size() > 1 and *s.begin() <= i or query(*s.begin()).F == p.F) s.erase(s.begin());
			int l = i + 1, r = *s.lower_bound(l);
			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 {
					if(v.F + v.S == mx) s.insert(m);
					r = m;
				}
			}
			if(l < n) {
				OK.push_back({l, query(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

prize.cpp: In function 'int find_best(int)':
prize.cpp:35:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    while(s.size() > 1 and *s.begin() <= i or query(*s.begin()).F == p.F) s.erase(s.begin());
          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
prize.cpp:38:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l + r >> 1;
             ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 256 KB Integer 200000 violates the range [0, 199999]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 412 KB Integer 200000 violates the range [0, 199999]
2 Halted 0 ms 0 KB -