Submission #139968

# Submission time Handle Problem Language Result Execution time Memory
139968 2019-08-01T18:26:54 Z arthurconmy The Big Prize (IOI17_prize) C++14
90 / 100
98 ms 2192 KB
#include <bits/stdc++.h>

#ifndef ARTHUR_LOCAL
	#include "prize.h"
#endif

using namespace std;

// NB: ask(i) returns a two-elem vector<int>

const int MAXN=200000;

bool asked[MAXN];
pair<int,int> answers[MAXN];

#ifdef ARTHUR_LOCAL
	vector<int> real_deal;

	vector<int> ask(int n)
	{
		int ans1=0;
		int ans2=0;

		for(int i=0; i<n; i++)
		{
			if(real_deal[i]<real_deal[n]) ans1++;
		}

		for(int i=n; i<8; i++)
		{
			if(real_deal[i]<real_deal[n]) ans2++;
		}

		return {ans1,ans2};
	}
#endif

pair<int,int> get_ans(int n)
{	
	//cout << n << endl;

	if(asked[n]) return answers[n];

	// cout << "Q!" << endl;

	asked[n]=1;
	vector<int> cur = ask(n);
	answers[n] = {cur[0],cur[1]};
	return answers[n];
}	

int find_best(int n) 
{
	// query 30 random places in order to determine the minimum thing

	random_device rd;  
    mt19937 gen(rd()); 
    uniform_int_distribution<> dis(1,1000000000);

	int max_side=0;

	for(int i=0; i<1000; i++) // should be less than 2**(-30) of failure to find the right value
	{
		pair<int,int> cur = get_ans(dis(gen)%n);
		max_side = max(max_side,cur.first+cur.second);
	}

	int left = 0;
	int right = n-1;

	while(true)
	{
		pair<int,int> cur = get_ans(left);

		if(cur.first + cur.second == 0) return left;
		if(cur.first + cur.second == max_side) break;

		left++;
	}

	while(true)
	{
		pair<int,int> cur = get_ans(right);

		if(cur.first + cur.second == 0) return right;
		if(cur.first + cur.second == max_side) break;

		right--;
	}

	//cout << left << " " << right << endl;

	vector<pair<int,int>> I = {make_pair(left,right)};

	while(true)
	{
		vector<pair<int,int>> new_I;

		for(auto i:I)
		{
			int left = i.first;
			int right = i.second;

			// cout << left << " " << right << endl;

			int lmid = int((left+right)/2);
			int rmid = lmid + 1;

			bool do_left=1;
			bool do_right=1;

			while(true)
			{
				pair<int,int> cur = get_ans(lmid);

				if(cur.first + cur.second == 0) return lmid;
				if(cur.first + cur.second == max_side) break;

				if(cur.first == 0) do_left=0;
				if(cur.second == 0) do_right=0;

				// if(get_ans(lmid).first == get_ans(left).first) break;

				lmid--;
			}

			while(true)
			{
				pair<int,int> cur = get_ans(rmid);

				if(cur.first + cur.second == 0) return rmid;
				if(cur.first + cur.second == max_side) break;

				if(cur.first == 0) do_left=0;
				if(cur.second == 0) do_right=0;

				// if(get_ans(right).first == get_ans(rmid).first) break;

				rmid++;
			}

			//cout << "LR: " << lmid << " " << rmid << endl;

			if(do_left && get_ans(lmid).first > get_ans(left).first) new_I.push_back({left,lmid});
			if(do_right && get_ans(right).first > get_ans(rmid).first) new_I.push_back({rmid,right});
		}

		I = new_I;
	}
}

#ifdef ARTHUR_LOCAL

	int main()
	{
		//cout << sqrt(200000) << endl;

		real_deal = {1,2,2,3,3,3,3,3};

		do
		{
			for(int i=0; i<8; i++)
			{
				asked[i]=0;
			}

			//for(auto i:real_deal) cout << i << " ";
			cout << endl << find_best(8) << endl;

		} while(next_permutation(real_deal.begin(),real_deal.end()));
	}
#endif
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1912 KB Output is correct
2 Correct 12 ms 1912 KB Output is correct
3 Correct 10 ms 1916 KB Output is correct
4 Correct 16 ms 1912 KB Output is correct
5 Correct 9 ms 1996 KB Output is correct
6 Correct 11 ms 2028 KB Output is correct
7 Correct 9 ms 1984 KB Output is correct
8 Correct 14 ms 1912 KB Output is correct
9 Correct 15 ms 1912 KB Output is correct
10 Correct 13 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1912 KB Output is correct
2 Correct 8 ms 2008 KB Output is correct
3 Correct 15 ms 1912 KB Output is correct
4 Correct 16 ms 1912 KB Output is correct
5 Correct 8 ms 1940 KB Output is correct
6 Correct 8 ms 1888 KB Output is correct
7 Correct 14 ms 1936 KB Output is correct
8 Correct 8 ms 1912 KB Output is correct
9 Correct 8 ms 1952 KB Output is correct
10 Correct 13 ms 1872 KB Output is correct
11 Correct 21 ms 1912 KB Output is correct
12 Correct 17 ms 1976 KB Output is correct
13 Correct 12 ms 2056 KB Output is correct
14 Correct 19 ms 504 KB Output is correct
15 Partially correct 54 ms 2100 KB Partially correct - number of queries: 7121
16 Partially correct 74 ms 1980 KB Partially correct - number of queries: 7346
17 Partially correct 76 ms 2040 KB Partially correct - number of queries: 6647
18 Partially correct 92 ms 2040 KB Partially correct - number of queries: 8480
19 Partially correct 88 ms 2040 KB Partially correct - number of queries: 7156
20 Correct 59 ms 1144 KB Output is correct
21 Partially correct 67 ms 2124 KB Partially correct - number of queries: 7737
22 Partially correct 34 ms 2012 KB Partially correct - number of queries: 6133
23 Correct 11 ms 1976 KB Output is correct
24 Correct 21 ms 1912 KB Output is correct
25 Partially correct 77 ms 2092 KB Partially correct - number of queries: 7239
26 Partially correct 88 ms 2168 KB Partially correct - number of queries: 7567
27 Correct 25 ms 1912 KB Output is correct
28 Partially correct 42 ms 2152 KB Partially correct - number of queries: 7703
29 Partially correct 57 ms 2160 KB Partially correct - number of queries: 6632
30 Partially correct 97 ms 2088 KB Partially correct - number of queries: 8445
31 Partially correct 77 ms 2040 KB Partially correct - number of queries: 7420
32 Correct 13 ms 1968 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Partially correct 82 ms 2088 KB Partially correct - number of queries: 7728
35 Correct 20 ms 1912 KB Output is correct
36 Partially correct 37 ms 2116 KB Partially correct - number of queries: 6824
37 Correct 21 ms 1960 KB Output is correct
38 Correct 17 ms 1832 KB Output is correct
39 Partially correct 98 ms 2040 KB Partially correct - number of queries: 7805
40 Partially correct 89 ms 2088 KB Partially correct - number of queries: 6668
41 Partially correct 84 ms 2040 KB Partially correct - number of queries: 7941
42 Partially correct 43 ms 2004 KB Partially correct - number of queries: 7943
43 Partially correct 76 ms 2032 KB Partially correct - number of queries: 7735
44 Partially correct 61 ms 2020 KB Partially correct - number of queries: 7807
45 Partially correct 42 ms 2076 KB Partially correct - number of queries: 7517
46 Partially correct 72 ms 2040 KB Partially correct - number of queries: 6659
47 Partially correct 74 ms 2040 KB Partially correct - number of queries: 7679
48 Partially correct 82 ms 2088 KB Partially correct - number of queries: 8048
49 Partially correct 75 ms 2040 KB Partially correct - number of queries: 7612
50 Partially correct 78 ms 2040 KB Partially correct - number of queries: 8263
51 Partially correct 80 ms 2044 KB Partially correct - number of queries: 8328
52 Partially correct 87 ms 2068 KB Partially correct - number of queries: 8331
53 Correct 16 ms 2040 KB Output is correct
54 Correct 26 ms 2120 KB Output is correct
55 Partially correct 71 ms 2040 KB Partially correct - number of queries: 6651
56 Partially correct 72 ms 2040 KB Partially correct - number of queries: 8359
57 Partially correct 68 ms 2168 KB Partially correct - number of queries: 8214
58 Partially correct 75 ms 2116 KB Partially correct - number of queries: 8414
59 Partially correct 44 ms 2112 KB Partially correct - number of queries: 7964
60 Partially correct 59 ms 2048 KB Partially correct - number of queries: 8293
61 Correct 16 ms 1912 KB Output is correct
62 Correct 9 ms 2016 KB Output is correct
63 Correct 19 ms 1912 KB Output is correct
64 Correct 9 ms 2012 KB Output is correct
65 Correct 14 ms 1912 KB Output is correct
66 Correct 16 ms 2040 KB Output is correct
67 Correct 19 ms 1936 KB Output is correct
68 Correct 18 ms 1912 KB Output is correct
69 Correct 8 ms 1968 KB Output is correct
70 Correct 15 ms 1912 KB Output is correct
71 Partially correct 89 ms 2040 KB Partially correct - number of queries: 9010
72 Correct 24 ms 1912 KB Output is correct
73 Partially correct 93 ms 2088 KB Partially correct - number of queries: 8909
74 Partially correct 86 ms 2040 KB Partially correct - number of queries: 8947
75 Correct 18 ms 1912 KB Output is correct
76 Partially correct 78 ms 2040 KB Partially correct - number of queries: 7990
77 Partially correct 69 ms 2172 KB Partially correct - number of queries: 8129
78 Correct 12 ms 2192 KB Output is correct
79 Correct 30 ms 2184 KB Output is correct
80 Partially correct 92 ms 2056 KB Partially correct - number of queries: 8100
81 Partially correct 51 ms 2060 KB Partially correct - number of queries: 8154
82 Partially correct 57 ms 2060 KB Partially correct - number of queries: 8131
83 Correct 20 ms 1912 KB Output is correct
84 Partially correct 48 ms 2056 KB Partially correct - number of queries: 7026
85 Partially correct 78 ms 2040 KB Partially correct - number of queries: 8149
86 Partially correct 76 ms 2088 KB Partially correct - number of queries: 7238
87 Correct 22 ms 1912 KB Output is correct
88 Partially correct 93 ms 2060 KB Partially correct - number of queries: 7041
89 Partially correct 72 ms 2168 KB Partially correct - number of queries: 7410
90 Correct 16 ms 1912 KB Output is correct
91 Partially correct 56 ms 2024 KB Partially correct - number of queries: 5150
92 Partially correct 54 ms 2040 KB Partially correct - number of queries: 5863
93 Partially correct 69 ms 1960 KB Partially correct - number of queries: 7174
94 Partially correct 75 ms 2160 KB Partially correct - number of queries: 7200
95 Partially correct 71 ms 2040 KB Partially correct - number of queries: 7245
96 Partially correct 50 ms 2084 KB Partially correct - number of queries: 7167
97 Correct 27 ms 2012 KB Output is correct