답안 #54233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54233 2018-07-02T21:23:04 Z radoslav11 커다란 상품 (IOI17_prize) C++14
97.63 / 100
132 ms 31564 KB
#include <bits/stdc++.h>
#include "prize.h"
//#include "Lgrader.cpp"

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

vector<int> memo[MAXN];
int Q = 0;
bool stop;
bool dummy[MAXN];

vector<int> query(int i) 
{
	if(!memo[i].empty()) return memo[i];
	if(stop || dummy[i]) return vector<int>(2, 1e9);
	
	memo[i] = ask(i), Q++;
	if(Q == 10000) assert(false);
	return memo[i];
}

void rec(int l, int r)
{
	if(r < l) return;

	if(query(l - 1)[0] + query(l - 1)[1] == 0) stop = 1;	
	if(query(r + 1)[0] + query(r + 1)[1] == 0) stop = 1;

	if(query(l - 1) == query(r + 1))
	{
		for(int i = l; i <= r; i++)
			memo[i] = query(l - 1);
		return;
	}

	int mid = (l + r) >> 1; 
	if(query(mid)[0] + query(mid)[1] == 0) stop = 1;
	if(query(l - 1) == query(mid))
		for(int i = l; i < mid; i++)
			memo[i] = query(mid);
	else
		rec(l, mid - 1);

	if(query(mid) == query(r + 1))
		for(int i = mid + 1; i <= r; i++)
			memo[i] = query(mid);
	else
		rec(mid + 1, r);
}

int find_best(int n) 
{
	/*int i = 0;
	while(i < n)
	{
		auto curr = query(i);
		if(curr[0] == 0 && curr[1] == 0)
			return i;

		int low = i, high = n - 1, mid, ret;
		for(int l = 0; low + (1 << l) < n; l++)
		{
			if(curr != query(low + (1 << l))) 
			{
				high = low + (1 << l);
				break;
			}
			
			low += (1 << l);
		}

		while(low <= high)
		{
			mid = (low + high) >> 1;
			if(curr == query(mid))
				low = mid + 1, ret = mid;
			else
				high = mid - 1;
		}

		i = ret + 1;
	}*/

	rec(1, n - 2);

	for(int i = 0; i < n; i++)
		if(query(i)[0] + query(i)[1] == 0)
			return i;

	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 31248 KB Output is correct
2 Correct 48 ms 31288 KB Output is correct
3 Correct 47 ms 31364 KB Output is correct
4 Correct 57 ms 31364 KB Output is correct
5 Correct 46 ms 31364 KB Output is correct
6 Correct 37 ms 31396 KB Output is correct
7 Correct 48 ms 31396 KB Output is correct
8 Correct 48 ms 31396 KB Output is correct
9 Correct 44 ms 31420 KB Output is correct
10 Correct 56 ms 31420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 31420 KB Output is correct
2 Correct 49 ms 31420 KB Output is correct
3 Correct 46 ms 31420 KB Output is correct
4 Correct 56 ms 31420 KB Output is correct
5 Correct 60 ms 31420 KB Output is correct
6 Correct 43 ms 31420 KB Output is correct
7 Correct 46 ms 31420 KB Output is correct
8 Correct 55 ms 31536 KB Output is correct
9 Correct 46 ms 31536 KB Output is correct
10 Correct 57 ms 31536 KB Output is correct
11 Correct 61 ms 31536 KB Output is correct
12 Correct 43 ms 31536 KB Output is correct
13 Correct 60 ms 31536 KB Output is correct
14 Correct 27 ms 31536 KB Output is correct
15 Correct 49 ms 31536 KB Output is correct
16 Correct 94 ms 31536 KB Output is correct
17 Correct 36 ms 31536 KB Output is correct
18 Partially correct 91 ms 31564 KB Partially correct - number of queries: 5068
19 Correct 37 ms 31564 KB Output is correct
20 Correct 41 ms 31564 KB Output is correct
21 Correct 58 ms 31564 KB Output is correct
22 Correct 40 ms 31564 KB Output is correct
23 Correct 38 ms 31564 KB Output is correct
24 Correct 38 ms 31564 KB Output is correct
25 Correct 69 ms 31564 KB Output is correct
26 Correct 70 ms 31564 KB Output is correct
27 Correct 43 ms 31564 KB Output is correct
28 Correct 103 ms 31564 KB Output is correct
29 Correct 82 ms 31564 KB Output is correct
30 Partially correct 132 ms 31564 KB Partially correct - number of queries: 5022
31 Correct 37 ms 31564 KB Output is correct
32 Correct 53 ms 31564 KB Output is correct
33 Correct 22 ms 31564 KB Output is correct
34 Correct 66 ms 31564 KB Output is correct
35 Correct 59 ms 31564 KB Output is correct
36 Correct 53 ms 31564 KB Output is correct
37 Correct 43 ms 31564 KB Output is correct
38 Correct 48 ms 31564 KB Output is correct
39 Correct 74 ms 31564 KB Output is correct
40 Correct 104 ms 31564 KB Output is correct
41 Correct 77 ms 31564 KB Output is correct
42 Correct 72 ms 31564 KB Output is correct
43 Correct 76 ms 31564 KB Output is correct
44 Correct 63 ms 31564 KB Output is correct
45 Correct 58 ms 31564 KB Output is correct
46 Correct 36 ms 31564 KB Output is correct
47 Correct 68 ms 31564 KB Output is correct
48 Correct 98 ms 31564 KB Output is correct
49 Correct 42 ms 31564 KB Output is correct
50 Partially correct 103 ms 31564 KB Partially correct - number of queries: 5070
51 Correct 67 ms 31564 KB Output is correct
52 Correct 39 ms 31564 KB Output is correct
53 Correct 54 ms 31564 KB Output is correct
54 Correct 66 ms 31564 KB Output is correct
55 Correct 36 ms 31564 KB Output is correct
56 Partially correct 106 ms 31564 KB Partially correct - number of queries: 5069
57 Correct 77 ms 31564 KB Output is correct
58 Correct 66 ms 31564 KB Output is correct
59 Correct 71 ms 31564 KB Output is correct
60 Correct 69 ms 31564 KB Output is correct
61 Correct 56 ms 31564 KB Output is correct
62 Correct 41 ms 31564 KB Output is correct
63 Correct 56 ms 31564 KB Output is correct
64 Correct 48 ms 31564 KB Output is correct
65 Correct 56 ms 31564 KB Output is correct
66 Correct 61 ms 31564 KB Output is correct
67 Correct 55 ms 31564 KB Output is correct
68 Correct 37 ms 31564 KB Output is correct
69 Correct 60 ms 31564 KB Output is correct
70 Correct 63 ms 31564 KB Output is correct
71 Correct 102 ms 31564 KB Output is correct
72 Correct 62 ms 31564 KB Output is correct
73 Correct 99 ms 31564 KB Output is correct
74 Correct 79 ms 31564 KB Output is correct
75 Correct 57 ms 31564 KB Output is correct
76 Correct 96 ms 31564 KB Output is correct
77 Partially correct 98 ms 31564 KB Partially correct - number of queries: 5216
78 Correct 60 ms 31564 KB Output is correct
79 Correct 76 ms 31564 KB Output is correct
80 Partially correct 101 ms 31564 KB Partially correct - number of queries: 5237
81 Partially correct 81 ms 31564 KB Partially correct - number of queries: 5218
82 Partially correct 98 ms 31564 KB Partially correct - number of queries: 5216
83 Correct 57 ms 31564 KB Output is correct
84 Correct 77 ms 31564 KB Output is correct
85 Partially correct 116 ms 31564 KB Partially correct - number of queries: 5233
86 Correct 62 ms 31564 KB Output is correct
87 Correct 61 ms 31564 KB Output is correct
88 Correct 64 ms 31564 KB Output is correct
89 Correct 66 ms 31564 KB Output is correct
90 Correct 58 ms 31564 KB Output is correct
91 Correct 82 ms 31564 KB Output is correct
92 Correct 56 ms 31564 KB Output is correct
93 Correct 59 ms 31564 KB Output is correct
94 Correct 59 ms 31564 KB Output is correct
95 Correct 60 ms 31564 KB Output is correct
96 Correct 58 ms 31564 KB Output is correct
97 Correct 54 ms 31564 KB Output is correct