Submission #593847

# Submission time Handle Problem Language Result Execution time Memory
593847 2022-07-11T16:23:56 Z AlperenT The Big Prize (IOI17_prize) C++17
99.09 / 100
64 ms 932 KB
#include <bits/stdc++.h>
#include "prize.h"

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int int_rand(int a, int b){
	return uniform_int_distribution<int>(a, b)(rng);
}

const int TRYMAX = 450, K = 1600, DIFF = 10000;

int maxcnt = 0;

map<int, vector<int>> mp;

vector<int> query(int pos){
	if(mp.find(pos) == mp.end()) mp[pos] = ask(pos);

	return mp[pos];
}

int find_best(int n){
	set<int> st;

	while(st.size() < n && st.size() < TRYMAX) st.insert(int_rand(0, n - 1));

	for(auto i : st){
		vector<int> vec = query(i);

		maxcnt = max(maxcnt, vec[0] + vec[1]);
	}

	vector<bool> ismax(n, false);

	int pos = 0, prefix = 0;

	while(pos < n){
		vector<int> vec = query(pos);

		if(vec[0] + vec[1] != maxcnt){
			pos++;
			continue;
		}

		int l = pos - 1, r = min(pos + K, n);

		while(r - l > 1){
			int m = l + (r - l) / 2;

			auto it = mp.lower_bound(m);

			int m2 = m;

			if(it != mp.end()){
				if(it->first > l && it->first < r && abs(it->first - m) <= DIFF) m2 = it->first;
			}

			if(it != mp.begin()){
				if(prev(it)->first > l && prev(it)->first < r && abs(prev(it)->first - m) <= DIFF) m2 = prev(it)->first;
			}

			m = m2;

			vector<int> vec = query(m);

			if(vec[0] + vec[1] == maxcnt && (m + 1 - vec[0]) - prefix == m - pos + 1) l = m;
			else r = m;
		}

		prefix += (l - pos + 1);

		for(int i = pos; i <= l; i++) ismax[i] = true;

		pos = max(pos + 1, l + 1);
	}

	for(int i = 0; i < n; i++){
		if(!ismax[i]){
			vector<int> vec = query(i);

			if(vec[0] + vec[1] == 0) return i;
		}
	}

	return -1;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:27:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |  while(st.size() < n && st.size() < TRYMAX) st.insert(int_rand(0, n - 1));
      |        ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 456 KB Output is correct
2 Correct 20 ms 412 KB Output is correct
3 Correct 15 ms 480 KB Output is correct
4 Correct 25 ms 560 KB Output is correct
5 Correct 17 ms 540 KB Output is correct
6 Correct 18 ms 412 KB Output is correct
7 Correct 17 ms 472 KB Output is correct
8 Correct 8 ms 508 KB Output is correct
9 Correct 21 ms 416 KB Output is correct
10 Correct 17 ms 584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 420 KB Output is correct
2 Correct 12 ms 420 KB Output is correct
3 Correct 8 ms 592 KB Output is correct
4 Correct 13 ms 476 KB Output is correct
5 Correct 14 ms 436 KB Output is correct
6 Correct 11 ms 584 KB Output is correct
7 Correct 20 ms 392 KB Output is correct
8 Correct 13 ms 400 KB Output is correct
9 Correct 15 ms 436 KB Output is correct
10 Correct 12 ms 464 KB Output is correct
11 Correct 18 ms 516 KB Output is correct
12 Correct 9 ms 500 KB Output is correct
13 Correct 16 ms 456 KB Output is correct
14 Correct 9 ms 364 KB Output is correct
15 Correct 51 ms 772 KB Output is correct
16 Correct 30 ms 800 KB Output is correct
17 Correct 51 ms 848 KB Output is correct
18 Correct 54 ms 840 KB Output is correct
19 Correct 47 ms 772 KB Output is correct
20 Correct 22 ms 676 KB Output is correct
21 Correct 50 ms 812 KB Output is correct
22 Correct 47 ms 684 KB Output is correct
23 Correct 17 ms 400 KB Output is correct
24 Correct 19 ms 464 KB Output is correct
25 Correct 49 ms 740 KB Output is correct
26 Correct 64 ms 824 KB Output is correct
27 Correct 19 ms 448 KB Output is correct
28 Correct 25 ms 760 KB Output is correct
29 Correct 41 ms 668 KB Output is correct
30 Correct 52 ms 820 KB Output is correct
31 Correct 41 ms 780 KB Output is correct
32 Correct 15 ms 448 KB Output is correct
33 Correct 2 ms 312 KB Output is correct
34 Correct 23 ms 864 KB Output is correct
35 Correct 19 ms 488 KB Output is correct
36 Correct 28 ms 864 KB Output is correct
37 Correct 20 ms 432 KB Output is correct
38 Correct 18 ms 480 KB Output is correct
39 Correct 59 ms 772 KB Output is correct
40 Correct 45 ms 792 KB Output is correct
41 Correct 53 ms 912 KB Output is correct
42 Correct 62 ms 772 KB Output is correct
43 Correct 32 ms 792 KB Output is correct
44 Correct 22 ms 860 KB Output is correct
45 Correct 49 ms 768 KB Output is correct
46 Correct 62 ms 820 KB Output is correct
47 Correct 42 ms 724 KB Output is correct
48 Correct 38 ms 932 KB Output is correct
49 Correct 49 ms 800 KB Output is correct
50 Correct 41 ms 840 KB Output is correct
51 Correct 45 ms 788 KB Output is correct
52 Correct 43 ms 844 KB Output is correct
53 Correct 14 ms 408 KB Output is correct
54 Correct 42 ms 772 KB Output is correct
55 Correct 44 ms 840 KB Output is correct
56 Correct 42 ms 820 KB Output is correct
57 Correct 64 ms 840 KB Output is correct
58 Correct 58 ms 800 KB Output is correct
59 Correct 41 ms 840 KB Output is correct
60 Correct 56 ms 832 KB Output is correct
61 Correct 8 ms 508 KB Output is correct
62 Correct 18 ms 416 KB Output is correct
63 Correct 17 ms 412 KB Output is correct
64 Correct 16 ms 504 KB Output is correct
65 Correct 18 ms 488 KB Output is correct
66 Correct 13 ms 548 KB Output is correct
67 Correct 12 ms 548 KB Output is correct
68 Correct 11 ms 552 KB Output is correct
69 Correct 22 ms 476 KB Output is correct
70 Correct 22 ms 456 KB Output is correct
71 Correct 53 ms 844 KB Output is correct
72 Correct 23 ms 404 KB Output is correct
73 Correct 52 ms 788 KB Output is correct
74 Correct 50 ms 760 KB Output is correct
75 Correct 24 ms 484 KB Output is correct
76 Correct 37 ms 740 KB Output is correct
77 Partially correct 44 ms 860 KB Partially correct - number of queries: 5063
78 Correct 20 ms 468 KB Output is correct
79 Correct 35 ms 636 KB Output is correct
80 Partially correct 48 ms 784 KB Partially correct - number of queries: 5086
81 Partially correct 29 ms 824 KB Partially correct - number of queries: 5087
82 Partially correct 44 ms 864 KB Partially correct - number of queries: 5019
83 Correct 17 ms 452 KB Output is correct
84 Correct 32 ms 692 KB Output is correct
85 Partially correct 35 ms 916 KB Partially correct - number of queries: 5091
86 Correct 42 ms 752 KB Output is correct
87 Correct 19 ms 440 KB Output is correct
88 Correct 42 ms 648 KB Output is correct
89 Correct 39 ms 656 KB Output is correct
90 Correct 15 ms 456 KB Output is correct
91 Correct 32 ms 596 KB Output is correct
92 Correct 42 ms 672 KB Output is correct
93 Correct 48 ms 864 KB Output is correct
94 Correct 38 ms 820 KB Output is correct
95 Correct 44 ms 848 KB Output is correct
96 Correct 58 ms 868 KB Output is correct
97 Correct 23 ms 832 KB Output is correct