Submission #69349

# Submission time Handle Problem Language Result Execution time Memory
69349 2018-08-20T15:12:13 Z Noam527 The Big Prize (IOI17_prize) C++17
94.75 / 100
70 ms 1212 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 + 666);
		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 4 ms 440 KB Output is correct
2 Correct 8 ms 440 KB Output is correct
3 Correct 8 ms 444 KB Output is correct
4 Correct 8 ms 464 KB Output is correct
5 Correct 5 ms 516 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Correct 8 ms 612 KB Output is correct
8 Correct 5 ms 612 KB Output is correct
9 Correct 9 ms 612 KB Output is correct
10 Correct 10 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 612 KB Output is correct
2 Correct 9 ms 612 KB Output is correct
3 Correct 9 ms 612 KB Output is correct
4 Correct 5 ms 612 KB Output is correct
5 Correct 15 ms 612 KB Output is correct
6 Correct 3 ms 612 KB Output is correct
7 Correct 5 ms 624 KB Output is correct
8 Correct 13 ms 624 KB Output is correct
9 Correct 11 ms 624 KB Output is correct
10 Correct 9 ms 624 KB Output is correct
11 Correct 15 ms 624 KB Output is correct
12 Correct 6 ms 624 KB Output is correct
13 Correct 15 ms 624 KB Output is correct
14 Correct 8 ms 624 KB Output is correct
15 Correct 18 ms 684 KB Output is correct
16 Correct 36 ms 1056 KB Output is correct
17 Correct 5 ms 1056 KB Output is correct
18 Partially correct 57 ms 1084 KB Partially correct - number of queries: 5357
19 Correct 6 ms 1084 KB Output is correct
20 Correct 18 ms 1084 KB Output is correct
21 Correct 13 ms 1084 KB Output is correct
22 Correct 11 ms 1084 KB Output is correct
23 Correct 4 ms 1084 KB Output is correct
24 Correct 7 ms 1084 KB Output is correct
25 Correct 32 ms 1084 KB Output is correct
26 Correct 26 ms 1084 KB Output is correct
27 Correct 9 ms 1084 KB Output is correct
28 Correct 54 ms 1084 KB Output is correct
29 Correct 50 ms 1084 KB Output is correct
30 Partially correct 64 ms 1176 KB Partially correct - number of queries: 5321
31 Correct 6 ms 1176 KB Output is correct
32 Correct 11 ms 1176 KB Output is correct
33 Correct 3 ms 1176 KB Output is correct
34 Correct 24 ms 1176 KB Output is correct
35 Correct 11 ms 1176 KB Output is correct
36 Correct 22 ms 1176 KB Output is correct
37 Correct 7 ms 1176 KB Output is correct
38 Correct 7 ms 1176 KB Output is correct
39 Correct 30 ms 1176 KB Output is correct
40 Correct 51 ms 1176 KB Output is correct
41 Correct 35 ms 1176 KB Output is correct
42 Correct 32 ms 1176 KB Output is correct
43 Correct 34 ms 1176 KB Output is correct
44 Correct 29 ms 1176 KB Output is correct
45 Correct 20 ms 1176 KB Output is correct
46 Correct 6 ms 1176 KB Output is correct
47 Correct 27 ms 1176 KB Output is correct
48 Correct 44 ms 1176 KB Output is correct
49 Correct 12 ms 1176 KB Output is correct
50 Partially correct 64 ms 1176 KB Partially correct - number of queries: 5372
51 Correct 28 ms 1176 KB Output is correct
52 Correct 8 ms 1176 KB Output is correct
53 Correct 11 ms 1176 KB Output is correct
54 Correct 29 ms 1176 KB Output is correct
55 Correct 6 ms 1176 KB Output is correct
56 Partially correct 66 ms 1176 KB Partially correct - number of queries: 5377
57 Correct 40 ms 1176 KB Output is correct
58 Correct 38 ms 1176 KB Output is correct
59 Correct 31 ms 1176 KB Output is correct
60 Correct 25 ms 1176 KB Output is correct
61 Correct 11 ms 1176 KB Output is correct
62 Correct 4 ms 1176 KB Output is correct
63 Correct 14 ms 1176 KB Output is correct
64 Correct 12 ms 1176 KB Output is correct
65 Correct 7 ms 1176 KB Output is correct
66 Correct 7 ms 1176 KB Output is correct
67 Correct 8 ms 1176 KB Output is correct
68 Correct 12 ms 1176 KB Output is correct
69 Correct 8 ms 1176 KB Output is correct
70 Correct 16 ms 1176 KB Output is correct
71 Partially correct 50 ms 1176 KB Partially correct - number of queries: 5348
72 Correct 7 ms 1176 KB Output is correct
73 Partially correct 60 ms 1176 KB Partially correct - number of queries: 5285
74 Partially correct 44 ms 1176 KB Partially correct - number of queries: 5312
75 Correct 10 ms 1176 KB Output is correct
76 Correct 23 ms 1176 KB Output is correct
77 Partially correct 59 ms 1176 KB Partially correct - number of queries: 5503
78 Correct 8 ms 1176 KB Output is correct
79 Correct 30 ms 1176 KB Output is correct
80 Partially correct 70 ms 1176 KB Partially correct - number of queries: 5508
81 Partially correct 59 ms 1176 KB Partially correct - number of queries: 5525
82 Partially correct 29 ms 1212 KB Partially correct - number of queries: 5447
83 Correct 13 ms 1212 KB Output is correct
84 Correct 49 ms 1212 KB Output is correct
85 Partially correct 63 ms 1212 KB Partially correct - number of queries: 5470
86 Correct 12 ms 1212 KB Output is correct
87 Correct 10 ms 1212 KB Output is correct
88 Correct 6 ms 1212 KB Output is correct
89 Correct 5 ms 1212 KB Output is correct
90 Correct 11 ms 1212 KB Output is correct
91 Correct 14 ms 1212 KB Output is correct
92 Correct 12 ms 1212 KB Output is correct
93 Correct 11 ms 1212 KB Output is correct
94 Correct 12 ms 1212 KB Output is correct
95 Correct 11 ms 1212 KB Output is correct
96 Correct 14 ms 1212 KB Output is correct
97 Correct 9 ms 1212 KB Output is correct