Submission #69346

# Submission time Handle Problem Language Result Execution time Memory
69346 2018-08-20T15:08:21 Z Noam527 The Big Prize (IOI17_prize) C++17
97.02 / 100
83 ms 1152 KB
#include "prize.h"
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7, inf = 1e9 + 7;
const ll hs = 199;
const ldb eps = 1e-9, pi = acos(-1);
using namespace std;
/*
vector<int> ask(int i) {
	cout << "? " << i << endl;
	vector<int> rtn(2);
	cin >> rtn[0] >> rtn[1];
	return rtn;
}
*/

map<int, vector<int>> alreadyfound;
vector<int> Q(int i) {
	if (alreadyfound.count(i)) return alreadyfound[i];
	return alreadyfound[i] = ask(i);
}

int N, badval;

bool bad(vector<int> a) {
	return a[0] + a[1] == badval;
}
bool answer(vector<int> a) {
	return a[0] + a[1] == 0;
}
// finds next bad position after pos. assumes it exists.
pair<int, vector<int>> findnext(int pos) {
	vector<int> a;
	while (!bad(a = Q(pos))) {
		if (answer(a)) return{ pos, a };
		pos++;
	}
	return{ pos, a };
}
// returns the ? in (val, val, ?, val + 1, ...). ? is the first in the sequence.
int calc(int l, int r, int val) {
	pair<int, vector<int>> b;
	int mid;
	while (l < r) {
		mid = (l + r + 1) / 2;
		b = findnext(mid);
		if (answer(b.second)) return b.first;
		if (val < b.second[0]) r = mid - 1;
		else l = mid;
	}
	return l;
}

int find_best(int n) {
	alreadyfound.clear();
	vector<int> a;
	if (n <= 5000) {
		for (int i = 0; i < n; i++) {
			a = ask(i);
			if (a[0] + a[1] == 0) return i;
		}
	}
	
	for (int i = 0; i < 500; i++) {
		auto something = Q(i);
		if (answer(something)) return i;
		badval = max(badval, something[0] + something[1]);
	}
	
	N = n;
	int l = 0, r = n - 1;
	while (!bad(a = Q(l))) {
		if (answer(a)) return l;
		l++;
	}
	while (!bad(a = Q(r))) {
		if (answer(a)) return r;
		r--;
	}
	int st = l, en, cnt;
	pair<int, vector<int>> b;
	while (st <= r) {
		en = min(r, st + 512);
		b = findnext(st);
		if (answer(b.second)) return b.first;
		st = b.first;
		b = findnext(en);
		if (answer(b.second)) return b.first;
		cnt = b.second[0] - Q(st)[0] - (b.first - en);
		for (int i = 0, tmp; i < cnt; i++) {
			tmp = calc(st, en, Q(st)[0] + i);
			if (answer(Q(tmp))) return tmp;
			if (answer(Q(tmp + 1))) return tmp + 1;
		}
		st = b.first;
	}
	return -1;
}
/*
int main() {
	int n;
	cin >> n;
	cout << find_best(n) << endl;
	cout << "^ is my answer" << endl;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 8 ms 252 KB Output is correct
2 Correct 10 ms 436 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 8 ms 512 KB Output is correct
5 Correct 9 ms 536 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 9 ms 536 KB Output is correct
8 Correct 8 ms 572 KB Output is correct
9 Correct 8 ms 700 KB Output is correct
10 Correct 9 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 700 KB Output is correct
2 Correct 12 ms 700 KB Output is correct
3 Correct 5 ms 700 KB Output is correct
4 Correct 9 ms 700 KB Output is correct
5 Correct 10 ms 700 KB Output is correct
6 Correct 3 ms 700 KB Output is correct
7 Correct 5 ms 736 KB Output is correct
8 Correct 6 ms 736 KB Output is correct
9 Correct 13 ms 736 KB Output is correct
10 Correct 9 ms 736 KB Output is correct
11 Correct 9 ms 736 KB Output is correct
12 Correct 4 ms 736 KB Output is correct
13 Correct 20 ms 736 KB Output is correct
14 Correct 6 ms 736 KB Output is correct
15 Correct 26 ms 736 KB Output is correct
16 Correct 44 ms 944 KB Output is correct
17 Correct 10 ms 944 KB Output is correct
18 Partially correct 57 ms 1084 KB Partially correct - number of queries: 5236
19 Correct 7 ms 1084 KB Output is correct
20 Correct 14 ms 1084 KB Output is correct
21 Correct 18 ms 1084 KB Output is correct
22 Correct 9 ms 1084 KB Output is correct
23 Correct 6 ms 1084 KB Output is correct
24 Correct 5 ms 1084 KB Output is correct
25 Correct 27 ms 1084 KB Output is correct
26 Correct 32 ms 1084 KB Output is correct
27 Correct 8 ms 1084 KB Output is correct
28 Correct 39 ms 1084 KB Output is correct
29 Correct 34 ms 1084 KB Output is correct
30 Partially correct 52 ms 1084 KB Partially correct - number of queries: 5109
31 Correct 4 ms 1084 KB Output is correct
32 Correct 10 ms 1084 KB Output is correct
33 Correct 2 ms 1084 KB Output is correct
34 Correct 23 ms 1084 KB Output is correct
35 Correct 11 ms 1084 KB Output is correct
36 Correct 23 ms 1084 KB Output is correct
37 Correct 8 ms 1084 KB Output is correct
38 Correct 7 ms 1084 KB Output is correct
39 Correct 26 ms 1084 KB Output is correct
40 Correct 64 ms 1084 KB Output is correct
41 Correct 39 ms 1084 KB Output is correct
42 Correct 31 ms 1084 KB Output is correct
43 Correct 33 ms 1084 KB Output is correct
44 Correct 21 ms 1084 KB Output is correct
45 Correct 19 ms 1084 KB Output is correct
46 Correct 8 ms 1084 KB Output is correct
47 Correct 26 ms 1084 KB Output is correct
48 Correct 45 ms 1084 KB Output is correct
49 Correct 14 ms 1084 KB Output is correct
50 Partially correct 29 ms 1152 KB Partially correct - number of queries: 5222
51 Correct 25 ms 1152 KB Output is correct
52 Correct 9 ms 1152 KB Output is correct
53 Correct 13 ms 1152 KB Output is correct
54 Correct 23 ms 1152 KB Output is correct
55 Correct 7 ms 1152 KB Output is correct
56 Partially correct 83 ms 1152 KB Partially correct - number of queries: 5224
57 Correct 20 ms 1152 KB Output is correct
58 Correct 46 ms 1152 KB Output is correct
59 Correct 24 ms 1152 KB Output is correct
60 Correct 43 ms 1152 KB Output is correct
61 Correct 10 ms 1152 KB Output is correct
62 Correct 7 ms 1152 KB Output is correct
63 Correct 14 ms 1152 KB Output is correct
64 Correct 11 ms 1152 KB Output is correct
65 Correct 9 ms 1152 KB Output is correct
66 Correct 15 ms 1152 KB Output is correct
67 Correct 9 ms 1152 KB Output is correct
68 Correct 5 ms 1152 KB Output is correct
69 Correct 8 ms 1152 KB Output is correct
70 Correct 8 ms 1152 KB Output is correct
71 Partially correct 53 ms 1152 KB Partially correct - number of queries: 5057
72 Correct 17 ms 1152 KB Output is correct
73 Partially correct 39 ms 1152 KB Partially correct - number of queries: 5001
74 Partially correct 48 ms 1152 KB Partially correct - number of queries: 5025
75 Correct 11 ms 1152 KB Output is correct
76 Correct 54 ms 1152 KB Output is correct
77 Partially correct 73 ms 1152 KB Partially correct - number of queries: 5298
78 Correct 16 ms 1152 KB Output is correct
79 Correct 44 ms 1152 KB Output is correct
80 Partially correct 69 ms 1152 KB Partially correct - number of queries: 5295
81 Partially correct 26 ms 1152 KB Partially correct - number of queries: 5249
82 Partially correct 58 ms 1152 KB Partially correct - number of queries: 5230
83 Correct 15 ms 1152 KB Output is correct
84 Correct 54 ms 1152 KB Output is correct
85 Partially correct 44 ms 1152 KB Partially correct - number of queries: 5263
86 Correct 16 ms 1152 KB Output is correct
87 Correct 17 ms 1152 KB Output is correct
88 Correct 11 ms 1152 KB Output is correct
89 Correct 16 ms 1152 KB Output is correct
90 Correct 13 ms 1152 KB Output is correct
91 Correct 14 ms 1152 KB Output is correct
92 Correct 14 ms 1152 KB Output is correct
93 Correct 16 ms 1152 KB Output is correct
94 Correct 18 ms 1152 KB Output is correct
95 Correct 14 ms 1152 KB Output is correct
96 Correct 15 ms 1152 KB Output is correct
97 Correct 14 ms 1152 KB Output is correct