Submission #834561

# Submission time Handle Problem Language Result Execution time Memory
834561 2023-08-22T15:27:43 Z Josia The Big Prize (IOI17_prize) C++17
100 / 100
77 ms 1440 KB
#include "prize.h"
using namespace std;
#include <bits/stdc++.h>


int numBetter = 0;
set<int> candidates;

map<int, vector<int>> rem;

int getNumBetter(vector<int> x) {
	return x[0]+x[1];
}

int sol = -1;

vector<int> myAsk(int pos) {
	if (rem.count(pos)) return rem[pos];
	rem[pos] = ask(pos);
	return rem[pos];
}



int find_best(int n) {
	candidates.clear();
	sol=-1;
	rem.clear();
	numBetter=0;

	set<pair<int, vector<int>>> s;

	vector<int> queries;
	for (int i = 0; i<n; i+=max(1,n/500)) {
		int hereBetter = getNumBetter(myAsk(i));
		queries.push_back(i);
		if (sol != -1) return sol;
		if (hereBetter > numBetter) {
			numBetter = hereBetter;
		}
	}

	for (int i: queries) {
		if (getNumBetter(myAsk(i)) == numBetter) s.insert({i, myAsk(i)});
	}



	int ahhhh = 0;
	while (getNumBetter(myAsk(ahhhh)) < numBetter) {
		candidates.insert(ahhhh);
		ahhhh++;
	}
	s.insert({ahhhh, myAsk(ahhhh)});
	ahhhh = n-1;
	while (getNumBetter(myAsk(ahhhh)) < numBetter) {
		candidates.insert(ahhhh);
		ahhhh--;
	}
	s.insert({ahhhh, myAsk(ahhhh)});


	for (int i = 0; i<100; i++) {
		auto p = s.begin();

		while (next(p) != s.end()) {
			if((*p).second[0] != (*next(p)).second[0]) {
				int m = ((*p).first + (*next(p)).first)/2;

				int inc = rand()%2;
				while (getNumBetter(myAsk(m)) < numBetter) {
					candidates.insert(m);
					m+=1-2*inc;
				}
				s.insert({m, myAsk(m)});
			}
			p++;
		}
	}


	for (int i: candidates) {
		if (getNumBetter(myAsk(i)) == 0) return i;
	}

	assert(0);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 3 ms 328 KB Output is correct
3 Correct 4 ms 288 KB Output is correct
4 Correct 5 ms 328 KB Output is correct
5 Correct 6 ms 336 KB Output is correct
6 Correct 6 ms 340 KB Output is correct
7 Correct 3 ms 312 KB Output is correct
8 Correct 5 ms 288 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 5 ms 272 KB Output is correct
3 Correct 4 ms 320 KB Output is correct
4 Correct 5 ms 336 KB Output is correct
5 Correct 4 ms 300 KB Output is correct
6 Correct 6 ms 332 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 7 ms 300 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 5 ms 352 KB Output is correct
11 Correct 10 ms 340 KB Output is correct
12 Correct 9 ms 448 KB Output is correct
13 Correct 6 ms 424 KB Output is correct
14 Correct 19 ms 464 KB Output is correct
15 Correct 73 ms 1192 KB Output is correct
16 Correct 70 ms 1180 KB Output is correct
17 Correct 50 ms 1248 KB Output is correct
18 Correct 76 ms 1296 KB Output is correct
19 Correct 67 ms 1176 KB Output is correct
20 Correct 41 ms 920 KB Output is correct
21 Correct 51 ms 1248 KB Output is correct
22 Correct 39 ms 1024 KB Output is correct
23 Correct 6 ms 292 KB Output is correct
24 Correct 6 ms 404 KB Output is correct
25 Correct 50 ms 1172 KB Output is correct
26 Correct 66 ms 1108 KB Output is correct
27 Correct 4 ms 336 KB Output is correct
28 Correct 65 ms 1172 KB Output is correct
29 Correct 55 ms 1036 KB Output is correct
30 Correct 65 ms 1224 KB Output is correct
31 Correct 61 ms 1180 KB Output is correct
32 Correct 9 ms 412 KB Output is correct
33 Correct 2 ms 304 KB Output is correct
34 Correct 57 ms 1268 KB Output is correct
35 Correct 4 ms 416 KB Output is correct
36 Correct 68 ms 1184 KB Output is correct
37 Correct 5 ms 460 KB Output is correct
38 Correct 6 ms 300 KB Output is correct
39 Correct 69 ms 1208 KB Output is correct
40 Correct 42 ms 1168 KB Output is correct
41 Correct 63 ms 1256 KB Output is correct
42 Correct 74 ms 1184 KB Output is correct
43 Correct 57 ms 1160 KB Output is correct
44 Correct 53 ms 1240 KB Output is correct
45 Correct 76 ms 1116 KB Output is correct
46 Correct 59 ms 1356 KB Output is correct
47 Correct 47 ms 1180 KB Output is correct
48 Correct 51 ms 1256 KB Output is correct
49 Correct 56 ms 1440 KB Output is correct
50 Correct 59 ms 1172 KB Output is correct
51 Correct 50 ms 1244 KB Output is correct
52 Correct 56 ms 1216 KB Output is correct
53 Correct 4 ms 404 KB Output is correct
54 Correct 54 ms 1312 KB Output is correct
55 Correct 70 ms 1264 KB Output is correct
56 Correct 59 ms 1180 KB Output is correct
57 Correct 67 ms 1204 KB Output is correct
58 Correct 63 ms 1292 KB Output is correct
59 Correct 77 ms 1200 KB Output is correct
60 Correct 67 ms 1224 KB Output is correct
61 Correct 4 ms 452 KB Output is correct
62 Correct 5 ms 336 KB Output is correct
63 Correct 6 ms 324 KB Output is correct
64 Correct 4 ms 392 KB Output is correct
65 Correct 4 ms 316 KB Output is correct
66 Correct 5 ms 412 KB Output is correct
67 Correct 5 ms 412 KB Output is correct
68 Correct 5 ms 404 KB Output is correct
69 Correct 11 ms 412 KB Output is correct
70 Correct 7 ms 420 KB Output is correct
71 Correct 68 ms 1264 KB Output is correct
72 Correct 7 ms 440 KB Output is correct
73 Correct 69 ms 1196 KB Output is correct
74 Correct 69 ms 1184 KB Output is correct
75 Correct 6 ms 336 KB Output is correct
76 Correct 54 ms 1140 KB Output is correct
77 Correct 76 ms 1216 KB Output is correct
78 Correct 8 ms 464 KB Output is correct
79 Correct 26 ms 880 KB Output is correct
80 Correct 73 ms 1200 KB Output is correct
81 Correct 63 ms 1260 KB Output is correct
82 Correct 68 ms 1284 KB Output is correct
83 Correct 4 ms 344 KB Output is correct
84 Correct 41 ms 1088 KB Output is correct
85 Correct 58 ms 1316 KB Output is correct
86 Correct 48 ms 1096 KB Output is correct
87 Correct 5 ms 432 KB Output is correct
88 Correct 53 ms 1084 KB Output is correct
89 Correct 61 ms 1176 KB Output is correct
90 Correct 5 ms 340 KB Output is correct
91 Correct 40 ms 888 KB Output is correct
92 Correct 61 ms 1176 KB Output is correct
93 Correct 74 ms 1180 KB Output is correct
94 Correct 74 ms 1248 KB Output is correct
95 Correct 74 ms 1200 KB Output is correct
96 Correct 70 ms 1220 KB Output is correct
97 Correct 52 ms 1220 KB Output is correct