답안 #136129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136129 2019-07-24T18:25:16 Z JustasZ 커다란 상품 (IOI17_prize) C++14
100 / 100
61 ms 976 KB
#include "prize.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
/*vector<int> ask(int i)
{
	cout << "? " << i << endl;
	vector<int>a(2);
	cin >> a[0] >> a[1];
	return a;
}*/
map<int, vector<int> >mp;
vector<int> askk(int i)
{
	if(!mp.count(i))
		mp[i] = ask(i);
	return mp[i];
}
int bl = 495;
int find_best(int n)
{
	vector<int>a, b;
	if(n <= 5000)
	{
		for(int i = 0; i < n; i++)
		{
			a = askk(i);
			if(a[0] + a[1] == 0)
				return i;
		}
	}
	int mx = 0, st = 500;
	for(int i = 0; i < min(n, 500); i++)
	{
		a = askk(i);
		if(a[0] + a[1] == 0)
			return i;
		if(a[0] + a[1] > 30)
		{
			mx = a[0] + a[1];
			st = i + 1;
			break;
		}
		mx = max(mx, a[0] + a[1]);
	}
	for(int i = st; i < n; i += bl)
	{
		int j = min(i + bl - 1, n - 1);
		int p = i;
		a = askk(p);
		while(a[0] + a[1] != mx)
		{
			if(a[0] + a[1] == 0)
				return p;
			p++;
			if(p > j)
				break;
			a = askk(p);
		}
		b = askk(j);
		while(b[0] + b[1] != mx)
		{
			if(b[0] + b[1] == 0)
				return j;
			j--;
			if(j < p)
				break;
			b = askk(j);
		}
		if(p < j)
		{
			int between = b[0] - a[0];
			if(between != 0)
			{
				int it = p;
				while(it < j && between > 0)
				{
					a = askk(it);
					if(a[0] + a[1] != mx)
					{
						between--;
						if(a[0] + a[1] == 0)
							return it;
					}
					else
					{
						int l = it + 1, r = j - 1;
						while(l < r)
						{
							int mid = (l + r) / 2;
							b = askk(mid);
							if(b[0] + b[1] != mx)
								r = mid;
							else
							{
								if(b[0] > a[0])
									r = mid - 1;
								else
									l = mid + 1;
							} 
						}
						it = l;
						a = askk(it);
						--between;
						if(a[0] + a[1] == 0)
							return it;
					}
					++it;
				}
			}
		}
	}
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:125:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 440 KB Output is correct
3 Correct 11 ms 376 KB Output is correct
4 Correct 17 ms 440 KB Output is correct
5 Correct 11 ms 376 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 12 ms 308 KB Output is correct
8 Correct 9 ms 436 KB Output is correct
9 Correct 11 ms 376 KB Output is correct
10 Correct 17 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 380 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 10 ms 376 KB Output is correct
4 Correct 18 ms 448 KB Output is correct
5 Correct 13 ms 376 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 12 ms 380 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 12 ms 376 KB Output is correct
10 Correct 14 ms 380 KB Output is correct
11 Correct 5 ms 412 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 13 ms 376 KB Output is correct
14 Correct 5 ms 248 KB Output is correct
15 Correct 10 ms 376 KB Output is correct
16 Correct 49 ms 716 KB Output is correct
17 Correct 2 ms 300 KB Output is correct
18 Correct 53 ms 760 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 12 ms 524 KB Output is correct
21 Correct 21 ms 504 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 5 ms 460 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 20 ms 600 KB Output is correct
26 Correct 17 ms 592 KB Output is correct
27 Correct 10 ms 388 KB Output is correct
28 Correct 31 ms 860 KB Output is correct
29 Correct 41 ms 612 KB Output is correct
30 Correct 55 ms 864 KB Output is correct
31 Correct 2 ms 380 KB Output is correct
32 Correct 11 ms 376 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 11 ms 472 KB Output is correct
35 Correct 16 ms 312 KB Output is correct
36 Correct 16 ms 380 KB Output is correct
37 Correct 5 ms 380 KB Output is correct
38 Correct 8 ms 376 KB Output is correct
39 Correct 27 ms 480 KB Output is correct
40 Correct 53 ms 688 KB Output is correct
41 Correct 30 ms 576 KB Output is correct
42 Correct 29 ms 616 KB Output is correct
43 Correct 23 ms 584 KB Output is correct
44 Correct 14 ms 560 KB Output is correct
45 Correct 18 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 24 ms 440 KB Output is correct
48 Correct 39 ms 724 KB Output is correct
49 Correct 6 ms 248 KB Output is correct
50 Correct 54 ms 776 KB Output is correct
51 Correct 23 ms 504 KB Output is correct
52 Correct 2 ms 248 KB Output is correct
53 Correct 15 ms 424 KB Output is correct
54 Correct 14 ms 592 KB Output is correct
55 Correct 2 ms 308 KB Output is correct
56 Correct 31 ms 852 KB Output is correct
57 Correct 40 ms 632 KB Output is correct
58 Correct 41 ms 704 KB Output is correct
59 Correct 33 ms 580 KB Output is correct
60 Correct 35 ms 552 KB Output is correct
61 Correct 9 ms 436 KB Output is correct
62 Correct 5 ms 440 KB Output is correct
63 Correct 16 ms 376 KB Output is correct
64 Correct 13 ms 376 KB Output is correct
65 Correct 10 ms 376 KB Output is correct
66 Correct 19 ms 504 KB Output is correct
67 Correct 15 ms 376 KB Output is correct
68 Correct 4 ms 352 KB Output is correct
69 Correct 10 ms 376 KB Output is correct
70 Correct 8 ms 516 KB Output is correct
71 Correct 31 ms 844 KB Output is correct
72 Correct 8 ms 520 KB Output is correct
73 Correct 53 ms 760 KB Output is correct
74 Correct 40 ms 976 KB Output is correct
75 Correct 17 ms 376 KB Output is correct
76 Correct 50 ms 768 KB Output is correct
77 Correct 51 ms 760 KB Output is correct
78 Correct 14 ms 504 KB Output is correct
79 Correct 34 ms 528 KB Output is correct
80 Correct 31 ms 896 KB Output is correct
81 Correct 61 ms 796 KB Output is correct
82 Correct 47 ms 932 KB Output is correct
83 Correct 17 ms 376 KB Output is correct
84 Correct 33 ms 856 KB Output is correct
85 Correct 50 ms 760 KB Output is correct
86 Correct 10 ms 508 KB Output is correct
87 Correct 13 ms 376 KB Output is correct
88 Correct 9 ms 512 KB Output is correct
89 Correct 9 ms 640 KB Output is correct
90 Correct 21 ms 376 KB Output is correct
91 Correct 15 ms 424 KB Output is correct
92 Correct 9 ms 516 KB Output is correct
93 Correct 13 ms 556 KB Output is correct
94 Correct 11 ms 564 KB Output is correct
95 Correct 18 ms 376 KB Output is correct
96 Correct 13 ms 376 KB Output is correct
97 Correct 16 ms 376 KB Output is correct