Submission #152448

# Submission time Handle Problem Language Result Execution time Memory
152448 2019-09-08T03:39:05 Z qkxwsm The Big Prize (IOI17_prize) C++14
97.58 / 100
69 ms 2180 KB
/*
PROG: template
LANG: C++11
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
 */
#include <bits/stdc++.h>
#include "prize.h"

using namespace std;

template<class T>
void readi(T &x)
{
	T input = 0;
	bool negative = false;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = input * 10 + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	x = input;
}
template<class T>
void printi(T output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long randomize(long long mod)
{
	return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-20;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 200013

long long normalize(long long x, long long mod = INF)
{
	return (((x % mod) + mod) % mod);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N, M;
bool vis[MAXN];
pii quer[MAXN];

void get(int idx)
{
	if (vis[idx])
	{
		return;
	}
	vis[idx] = true;
	vector<int> res = ask(idx);
	quer[idx] = MP(res[0], res[1]);
//	cerr << idx << ' ' << quer[idx].fi << ' ' << quer[idx].se << endl;
//	if (quer[idx].fi + quer[idx].se != M)
//	{
//		special[idx] = true;
////		cerr << "special " << idx << endl;
//	}
	return;
}
void solve(int L, int R)
{
	//guarantee that neither L, R are special and both are queried
	if (L > R) return;
	if (quer[L].fi == quer[R].fi) return;
//	cerr << "solve " << L << ' ' << R << endl;
	int mid;
	mid = (L + R)/2;
	for (; mid <= R; mid++)
	{
		get(mid);
		if (quer[mid].fi + quer[mid].se == M)
		{
			break;
		}
	}
	solve(mid, R);
	mid = (L + R)/2;
	for (; mid >= L; mid--)
	{
		get(mid);
		if (quer[mid].fi + quer[mid].se == M)
		{
			break;
		}
	}
	solve(L, mid);
	//at least one special guy in L...lmid - 1
}
int find_best(int n)
{
	//at most 6 distinct prizes
	//711 guys are not 6
	//query 712 times, then you get to know the location of a max
	//1, 2, 5, 26, 677, whatever
	//1, 3, 8, 34, 711, 200000
	N = n;
	if (N == 1) return 0;
	//question is: you want to query at most 5000 times and find the 1
	//find the locations of all the not1's in O(fast)
	//there are 711 flags in an array of 200000, can you find the locations of all of them, given how many are <= x
	for (int i = 0; i < min(240, N); i++)
	{
		get(i);
		ckmax(M, quer[i].fi + quer[i].se);
	}
	for (int i = 0; i < min(240, N); i++)
	{
		get(N - 1 - i);
		ckmax(M, quer[N - 1 - i].fi + quer[N - 1 - i].se);
	}
//	cerr << M << endl;
	int lt = 0, rt = N - 1;
	for (; lt < N; lt++)
	{
		get(lt);
		if (quer[lt].fi + quer[lt].se == M)
		{
			break;
		}
	}
	for (; rt >= 0; rt--)
	{
		get(rt);
		if (quer[rt].fi + quer[rt].se == M)
		{
			break;
		}
	}
//	cerr << lt << ' ' << rt << endl;
	solve(lt, rt);
	for (int i = 0; i < N; i++)
	{
		if (vis[i] && (quer[i].fi + quer[i].se != M))
		{
			get(i);
			if (quer[i].fi + quer[i].se == 0)
			{
				return i;
			}
		}
	}
	assert(false);
	//M is the # of special guys
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 6 ms 248 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 8 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 392 KB Output is correct
9 Correct 4 ms 392 KB Output is correct
10 Correct 8 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 276 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Correct 8 ms 376 KB Output is correct
4 Correct 6 ms 248 KB Output is correct
5 Correct 6 ms 328 KB Output is correct
6 Correct 5 ms 408 KB Output is correct
7 Correct 9 ms 376 KB Output is correct
8 Correct 8 ms 376 KB Output is correct
9 Correct 9 ms 248 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
11 Correct 19 ms 1016 KB Output is correct
12 Correct 7 ms 1120 KB Output is correct
13 Correct 14 ms 1144 KB Output is correct
14 Correct 15 ms 504 KB Output is correct
15 Correct 46 ms 2140 KB Output is correct
16 Partially correct 52 ms 2100 KB Partially correct - number of queries: 5131
17 Partially correct 42 ms 2000 KB Partially correct - number of queries: 5099
18 Partially correct 60 ms 2040 KB Partially correct - number of queries: 5101
19 Correct 68 ms 1964 KB Output is correct
20 Correct 33 ms 1132 KB Output is correct
21 Partially correct 47 ms 2048 KB Partially correct - number of queries: 5091
22 Correct 50 ms 2040 KB Output is correct
23 Correct 8 ms 588 KB Output is correct
24 Correct 10 ms 936 KB Output is correct
25 Correct 34 ms 1888 KB Output is correct
26 Correct 48 ms 1992 KB Output is correct
27 Correct 6 ms 560 KB Output is correct
28 Correct 55 ms 1912 KB Output is correct
29 Correct 43 ms 1896 KB Output is correct
30 Partially correct 54 ms 2032 KB Partially correct - number of queries: 5075
31 Partially correct 40 ms 2020 KB Partially correct - number of queries: 5069
32 Correct 11 ms 1016 KB Output is correct
33 Correct 3 ms 248 KB Output is correct
34 Partially correct 31 ms 2064 KB Partially correct - number of queries: 5113
35 Correct 10 ms 808 KB Output is correct
36 Partially correct 45 ms 1980 KB Partially correct - number of queries: 5043
37 Correct 14 ms 888 KB Output is correct
38 Correct 11 ms 556 KB Output is correct
39 Partially correct 55 ms 2040 KB Partially correct - number of queries: 5046
40 Correct 48 ms 1960 KB Output is correct
41 Partially correct 65 ms 2008 KB Partially correct - number of queries: 5090
42 Partially correct 52 ms 1960 KB Partially correct - number of queries: 5090
43 Correct 56 ms 1960 KB Output is correct
44 Partially correct 55 ms 2068 KB Partially correct - number of queries: 5114
45 Correct 28 ms 1984 KB Output is correct
46 Partially correct 49 ms 2004 KB Partially correct - number of queries: 5097
47 Correct 54 ms 1976 KB Output is correct
48 Partially correct 52 ms 1972 KB Partially correct - number of queries: 5087
49 Partially correct 30 ms 2008 KB Partially correct - number of queries: 5082
50 Partially correct 48 ms 2048 KB Partially correct - number of queries: 5109
51 Partially correct 59 ms 1976 KB Partially correct - number of queries: 5101
52 Partially correct 55 ms 1948 KB Partially correct - number of queries: 5119
53 Correct 10 ms 632 KB Output is correct
54 Partially correct 50 ms 1960 KB Partially correct - number of queries: 5084
55 Partially correct 45 ms 2004 KB Partially correct - number of queries: 5102
56 Partially correct 53 ms 1996 KB Partially correct - number of queries: 5083
57 Partially correct 54 ms 2040 KB Partially correct - number of queries: 5082
58 Partially correct 36 ms 2004 KB Partially correct - number of queries: 5091
59 Partially correct 62 ms 2040 KB Partially correct - number of queries: 5098
60 Partially correct 51 ms 2004 KB Partially correct - number of queries: 5042
61 Correct 10 ms 568 KB Output is correct
62 Correct 5 ms 624 KB Output is correct
63 Correct 9 ms 568 KB Output is correct
64 Correct 5 ms 540 KB Output is correct
65 Correct 8 ms 248 KB Output is correct
66 Correct 6 ms 520 KB Output is correct
67 Correct 10 ms 248 KB Output is correct
68 Correct 10 ms 252 KB Output is correct
69 Correct 9 ms 248 KB Output is correct
70 Correct 6 ms 248 KB Output is correct
71 Partially correct 69 ms 1960 KB Partially correct - number of queries: 5239
72 Correct 16 ms 1016 KB Output is correct
73 Partially correct 31 ms 2132 KB Partially correct - number of queries: 5176
74 Partially correct 60 ms 1988 KB Partially correct - number of queries: 5203
75 Correct 9 ms 632 KB Output is correct
76 Correct 45 ms 2056 KB Output is correct
77 Partially correct 32 ms 2052 KB Partially correct - number of queries: 5234
78 Correct 11 ms 1096 KB Output is correct
79 Correct 18 ms 2052 KB Output is correct
80 Partially correct 54 ms 1960 KB Partially correct - number of queries: 5242
81 Partially correct 31 ms 2180 KB Partially correct - number of queries: 5187
82 Partially correct 39 ms 1988 KB Partially correct - number of queries: 5129
83 Correct 9 ms 632 KB Output is correct
84 Correct 42 ms 2028 KB Output is correct
85 Partially correct 64 ms 1960 KB Partially correct - number of queries: 5178
86 Correct 9 ms 376 KB Output is correct
87 Correct 8 ms 376 KB Output is correct
88 Correct 8 ms 400 KB Output is correct
89 Correct 5 ms 412 KB Output is correct
90 Correct 5 ms 388 KB Output is correct
91 Correct 7 ms 376 KB Output is correct
92 Correct 7 ms 376 KB Output is correct
93 Correct 16 ms 760 KB Output is correct
94 Correct 7 ms 788 KB Output is correct
95 Correct 12 ms 828 KB Output is correct
96 Correct 11 ms 924 KB Output is correct
97 Correct 5 ms 328 KB Output is correct