Submission #425715

# Submission time Handle Problem Language Result Execution time Memory
425715 2021-06-13T10:27:27 Z NachoLibre The Big Prize (IOI17_prize) C++17
100 / 100
96 ms 11364 KB
#include <bits/stdc++.h>
using namespace std;
#define sz(a) ((int)(a).size())
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef long long ll;
#ifndef wambule
#include "prize.h"
#else
int _n;
vint _x;
vint ask(int i) {
	vint dr(2);
	for(int j = 0; j < _n; ++j) {
		if(_x[j] < _x[i]) ++dr[j > i];
	}
	return dr;
}
#endif

mt19937_64 rnd(time(0));
int R(int l, int r) {
	return l + rnd() % (r - l + 1);
}

int c;
vvint cch;
set<int> s;
vint A(int i) {
	if(cch[i][0] == -1) {
		// if(++c > 10000) exit(1);
		cch[i] = ask(i);
		s.insert(i);
	}
	return cch[i];
}

int find_best(int n) {
	c = 0;
	s.clear();
	cch.clear();
	cch.resize(n, vint(2, -1));
	int cm = 0;
	for(int i = 0; i < 100; ++i) {
		int x = R(0, n - 1);
		cm = max(cm, A(x)[0] + A(x)[1]);
		// if(A(x)[0] + A(x)[1] == +0) return x;
	}
	for(int i = 0; i < n; ++i) {
		#ifdef wambule
		cout << i << endl;
		#endif
		while(s.size() && (*s.begin()) <= i) {
			s.erase(s.begin());
		}
		if(A(i)[0] + A(i)[1] == +0) return i;
		if(A(i)[0] + A(i)[1] == cm) {
			int l = i, r = n - 1;
			while(s.size()) {
				int x = *s.begin();
				if(A(x)[1] == A(i)[1]) {
					s.erase(s.begin());
					l = x;
				} else {
					r = x - 1;
					break;
				}
			}
			#ifdef wambule
			cout << l << " " << r << endl;
			#endif
			while(l < r) {
				int m = l + r + 1 >> 1;
				while(A(m)[0] + A(m)[1] < cm) {
					--m;
					r = m;
				}
				if(A(m)[1] == A(i)[1]) l = m;
				else r = m - 1;
				#ifdef wambule
				cout << l << " " << r << endl;
				#endif
			}
			i = l;
		}
	}
	return 0;
}

#ifdef wambule
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	_x = {3, 2, 3, 1, 3, 3, 2, 3};
	_n = _x.size();
	cout << find_best(_n) << " " << c << " []" << endl;
	_x = {3, 3, 3, 2, 2, 3, 3, 1};
	_n = _x.size();
	cout << find_best(_n) << " " << c << " []" << endl;
	return 0;
}
#endif

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:73:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |     int m = l + r + 1 >> 1;
      |             ~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 11156 KB Output is correct
2 Correct 19 ms 11200 KB Output is correct
3 Correct 18 ms 11216 KB Output is correct
4 Correct 15 ms 11160 KB Output is correct
5 Correct 15 ms 11208 KB Output is correct
6 Correct 17 ms 11200 KB Output is correct
7 Correct 17 ms 11176 KB Output is correct
8 Correct 16 ms 11164 KB Output is correct
9 Correct 15 ms 11156 KB Output is correct
10 Correct 16 ms 11208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 11244 KB Output is correct
2 Correct 16 ms 11120 KB Output is correct
3 Correct 15 ms 11168 KB Output is correct
4 Correct 17 ms 11260 KB Output is correct
5 Correct 14 ms 11264 KB Output is correct
6 Correct 17 ms 11328 KB Output is correct
7 Correct 15 ms 11364 KB Output is correct
8 Correct 18 ms 11164 KB Output is correct
9 Correct 15 ms 11208 KB Output is correct
10 Correct 16 ms 11208 KB Output is correct
11 Correct 17 ms 11164 KB Output is correct
12 Correct 17 ms 11260 KB Output is correct
13 Correct 20 ms 11164 KB Output is correct
14 Correct 6 ms 1352 KB Output is correct
15 Correct 24 ms 11148 KB Output is correct
16 Correct 37 ms 11268 KB Output is correct
17 Correct 16 ms 11260 KB Output is correct
18 Correct 74 ms 11156 KB Output is correct
19 Correct 14 ms 11252 KB Output is correct
20 Correct 14 ms 5792 KB Output is correct
21 Correct 37 ms 11200 KB Output is correct
22 Correct 16 ms 11264 KB Output is correct
23 Correct 16 ms 11164 KB Output is correct
24 Correct 18 ms 11160 KB Output is correct
25 Correct 39 ms 11160 KB Output is correct
26 Correct 46 ms 11160 KB Output is correct
27 Correct 15 ms 11148 KB Output is correct
28 Correct 43 ms 11144 KB Output is correct
29 Correct 68 ms 11160 KB Output is correct
30 Correct 88 ms 11156 KB Output is correct
31 Correct 15 ms 11164 KB Output is correct
32 Correct 20 ms 11156 KB Output is correct
33 Correct 2 ms 200 KB Output is correct
34 Correct 41 ms 11168 KB Output is correct
35 Correct 22 ms 11164 KB Output is correct
36 Correct 30 ms 11152 KB Output is correct
37 Correct 18 ms 11240 KB Output is correct
38 Correct 17 ms 11160 KB Output is correct
39 Correct 44 ms 11148 KB Output is correct
40 Correct 58 ms 11144 KB Output is correct
41 Correct 54 ms 11160 KB Output is correct
42 Correct 66 ms 11160 KB Output is correct
43 Correct 54 ms 11172 KB Output is correct
44 Correct 39 ms 11156 KB Output is correct
45 Correct 27 ms 11120 KB Output is correct
46 Correct 18 ms 11144 KB Output is correct
47 Correct 44 ms 11224 KB Output is correct
48 Correct 58 ms 11148 KB Output is correct
49 Correct 19 ms 11156 KB Output is correct
50 Correct 68 ms 11328 KB Output is correct
51 Correct 25 ms 11316 KB Output is correct
52 Correct 18 ms 11168 KB Output is correct
53 Correct 17 ms 11156 KB Output is correct
54 Correct 28 ms 11308 KB Output is correct
55 Correct 17 ms 11252 KB Output is correct
56 Correct 62 ms 11164 KB Output is correct
57 Correct 33 ms 11264 KB Output is correct
58 Correct 33 ms 11264 KB Output is correct
59 Correct 38 ms 11264 KB Output is correct
60 Correct 29 ms 11268 KB Output is correct
61 Correct 17 ms 11200 KB Output is correct
62 Correct 16 ms 11160 KB Output is correct
63 Correct 17 ms 11248 KB Output is correct
64 Correct 17 ms 11160 KB Output is correct
65 Correct 19 ms 11208 KB Output is correct
66 Correct 21 ms 11200 KB Output is correct
67 Correct 17 ms 11160 KB Output is correct
68 Correct 23 ms 11160 KB Output is correct
69 Correct 20 ms 11160 KB Output is correct
70 Correct 16 ms 11160 KB Output is correct
71 Correct 44 ms 11268 KB Output is correct
72 Correct 21 ms 11164 KB Output is correct
73 Correct 96 ms 11208 KB Output is correct
74 Correct 71 ms 11264 KB Output is correct
75 Correct 18 ms 11168 KB Output is correct
76 Correct 69 ms 11208 KB Output is correct
77 Correct 67 ms 11208 KB Output is correct
78 Correct 18 ms 11208 KB Output is correct
79 Correct 45 ms 11244 KB Output is correct
80 Correct 86 ms 11196 KB Output is correct
81 Correct 84 ms 11164 KB Output is correct
82 Correct 54 ms 11264 KB Output is correct
83 Correct 17 ms 11208 KB Output is correct
84 Correct 59 ms 11232 KB Output is correct
85 Correct 63 ms 11208 KB Output is correct
86 Correct 42 ms 11208 KB Output is correct
87 Correct 16 ms 11308 KB Output is correct
88 Correct 35 ms 11224 KB Output is correct
89 Correct 35 ms 11172 KB Output is correct
90 Correct 19 ms 11208 KB Output is correct
91 Correct 21 ms 11328 KB Output is correct
92 Correct 19 ms 11260 KB Output is correct
93 Correct 21 ms 11268 KB Output is correct
94 Correct 20 ms 11200 KB Output is correct
95 Correct 20 ms 11148 KB Output is correct
96 Correct 18 ms 11208 KB Output is correct
97 Correct 14 ms 11300 KB Output is correct