Submission #727707

# Submission time Handle Problem Language Result Execution time Memory
727707 2023-04-21T06:35:11 Z jwvg0425 The Big Prize (IOI17_prize) C++17
90 / 100
59 ms 1240 KB
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include "prize.h"
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;

template<typename T, typename Pr = less<T>>
using pq = priority_queue<T, vector<T>, Pr>;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>; 

vector<ii> finded;
int bigSize;

random_device rd;
mt19937 mt(rd());
int outL, outR;

int cntl(int x)
{
	return upper_bound(all(finded), ii{ x, 1 << 30 }) - finded.begin() + outL;
}

int cntr(int x)
{
	return finded.end() - lower_bound(all(finded), ii{ x, -1 }) + outR;
}

bool test(int l, int r)
{
	if (l > r)
		return false;

	int m = (l + r) / 2;
	int ml = m;
	int mlL = 0, mlR = 0;

	while (ml >= l)
	{
		if (any_of(all(finded), [ml](ii x) { return x.xx == ml; }))
		{
			ml--;
			continue;
		}

		auto res = ask(ml);
		if (res[0] + res[1] != bigSize)
		{
			finded.insert(lower_bound(all(finded), ii{ ml, res[0] + res[1] }), ii{ ml, res[0] + res[1] });
			if (res[0] + res[1] == 0)
				return true;
			ml--;
		}
		else
		{
			mlL = res[0];
			mlR = res[1];
			break;
		}
	}

	if (ml > l && mlL != cntl(ml - 1))
		if (test(l, ml - 1))
			return true;

	if (m + 1 <= r && mlR - (m - ml) != cntr(m + 1))
		if (test(m + 1, r))
			return true;

	return false;
}

int find_best(int n)
{
	vector<int> indexs(n);
	for (int i = 0; i < n; i++)
		indexs[i] = i;
	vector<ii> ix;
	for (int i = 0; i < min(n, 600); i++)
	{
		auto q = ask(indexs[i]);
		if (q[0] + q[1] == 0)
			return i;

		ix.emplace_back(q[0] + q[1], indexs[i]);
	}

	sort(all(ix));

	bigSize = ix.back().xx;
	int bucket = 500;
	vector<int> bs;

	for (int i = 0; i < n; i += bucket)
		bs.push_back(i);

	shuffle(all(bs), mt);

	for (auto& bi : bs)
	{
		finded.clear();
		int l = bi, r = min(n - 1, bi + bucket - 1);

		while (l < r)
		{
			auto q = ask(l);
			if (q[0] + q[1] == 0)
				return l;

			if (q[0] + q[1] == bigSize)
			{
				outL = q[0];
				break;
			}

			l++;
		}

		while (l < r)
		{
			auto q = ask(r);
			if (q[0] + q[1] == 0)
				return r;

			if (q[0] + q[1] == bigSize)
			{
				outR = q[1];
				break;
			}

			r--;
		}

		// 한 개도 없는 구간 pass
		if (outL + outR == bigSize)
			continue;

		if (test(l + 1, r - 1))
		{
			for (auto& [k, v] : finded)
			{
				if (v == 0)
					return k;
			}
		}
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1104 KB Output is correct
2 Correct 11 ms 1120 KB Output is correct
3 Correct 8 ms 1104 KB Output is correct
4 Correct 9 ms 1072 KB Output is correct
5 Correct 13 ms 1096 KB Output is correct
6 Correct 1 ms 1072 KB Output is correct
7 Correct 6 ms 1076 KB Output is correct
8 Correct 6 ms 1072 KB Output is correct
9 Correct 9 ms 1104 KB Output is correct
10 Correct 6 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1068 KB Output is correct
2 Correct 4 ms 1240 KB Output is correct
3 Correct 7 ms 1104 KB Output is correct
4 Correct 13 ms 1104 KB Output is correct
5 Correct 8 ms 1060 KB Output is correct
6 Correct 1 ms 1068 KB Output is correct
7 Correct 5 ms 1096 KB Output is correct
8 Correct 12 ms 1112 KB Output is correct
9 Correct 11 ms 1104 KB Output is correct
10 Correct 12 ms 1104 KB Output is correct
11 Correct 16 ms 1104 KB Output is correct
12 Correct 11 ms 1060 KB Output is correct
13 Correct 10 ms 1068 KB Output is correct
14 Correct 16 ms 336 KB Output is correct
15 Correct 22 ms 1104 KB Output is correct
16 Correct 32 ms 1104 KB Output is correct
17 Correct 6 ms 1104 KB Output is correct
18 Partially correct 47 ms 1052 KB Partially correct - number of queries: 5304
19 Correct 5 ms 1064 KB Output is correct
20 Correct 38 ms 720 KB Output is correct
21 Correct 25 ms 1104 KB Output is correct
22 Correct 33 ms 1104 KB Output is correct
23 Correct 11 ms 1104 KB Output is correct
24 Correct 7 ms 1232 KB Output is correct
25 Partially correct 58 ms 1104 KB Partially correct - number of queries: 6054
26 Correct 21 ms 1068 KB Output is correct
27 Correct 6 ms 1072 KB Output is correct
28 Correct 19 ms 1068 KB Output is correct
29 Partially correct 36 ms 1104 KB Partially correct - number of queries: 5588
30 Partially correct 44 ms 1104 KB Partially correct - number of queries: 5882
31 Correct 3 ms 1108 KB Output is correct
32 Correct 16 ms 1068 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 24 ms 1048 KB Output is correct
35 Correct 11 ms 1064 KB Output is correct
36 Correct 15 ms 1104 KB Output is correct
37 Correct 7 ms 1064 KB Output is correct
38 Correct 7 ms 1072 KB Output is correct
39 Correct 44 ms 1104 KB Output is correct
40 Correct 8 ms 1068 KB Output is correct
41 Partially correct 51 ms 1104 KB Partially correct - number of queries: 6470
42 Partially correct 43 ms 1104 KB Partially correct - number of queries: 5672
43 Correct 35 ms 1104 KB Output is correct
44 Correct 33 ms 1096 KB Output is correct
45 Correct 17 ms 1104 KB Output is correct
46 Correct 2 ms 1088 KB Output is correct
47 Correct 14 ms 1064 KB Output is correct
48 Correct 36 ms 1076 KB Output is correct
49 Correct 20 ms 1104 KB Output is correct
50 Partially correct 49 ms 1104 KB Partially correct - number of queries: 6426
51 Correct 16 ms 1104 KB Output is correct
52 Correct 30 ms 1072 KB Output is correct
53 Correct 9 ms 1096 KB Output is correct
54 Partially correct 48 ms 1096 KB Partially correct - number of queries: 6235
55 Correct 6 ms 1112 KB Output is correct
56 Correct 26 ms 1096 KB Output is correct
57 Correct 39 ms 1104 KB Output is correct
58 Correct 16 ms 1112 KB Output is correct
59 Partially correct 59 ms 1104 KB Partially correct - number of queries: 6701
60 Correct 40 ms 1104 KB Output is correct
61 Correct 6 ms 1068 KB Output is correct
62 Correct 7 ms 1072 KB Output is correct
63 Correct 8 ms 1072 KB Output is correct
64 Correct 11 ms 1104 KB Output is correct
65 Correct 9 ms 1096 KB Output is correct
66 Correct 8 ms 1072 KB Output is correct
67 Correct 15 ms 1104 KB Output is correct
68 Correct 3 ms 1072 KB Output is correct
69 Correct 10 ms 1072 KB Output is correct
70 Correct 16 ms 1104 KB Output is correct
71 Partially correct 27 ms 1096 KB Partially correct - number of queries: 5267
72 Correct 18 ms 1108 KB Output is correct
73 Partially correct 40 ms 1108 KB Partially correct - number of queries: 5288
74 Partially correct 46 ms 1104 KB Partially correct - number of queries: 5082
75 Correct 12 ms 1104 KB Output is correct
76 Correct 35 ms 1104 KB Output is correct
77 Partially correct 39 ms 1104 KB Partially correct - number of queries: 5310
78 Correct 15 ms 1104 KB Output is correct
79 Correct 28 ms 1104 KB Output is correct
80 Partially correct 24 ms 1116 KB Partially correct - number of queries: 5410
81 Partially correct 40 ms 1104 KB Partially correct - number of queries: 5079
82 Correct 24 ms 1240 KB Output is correct
83 Correct 9 ms 1104 KB Output is correct
84 Correct 20 ms 1144 KB Output is correct
85 Partially correct 26 ms 1116 KB Partially correct - number of queries: 5082
86 Correct 8 ms 1104 KB Output is correct
87 Correct 10 ms 1104 KB Output is correct
88 Correct 17 ms 1104 KB Output is correct
89 Correct 11 ms 1112 KB Output is correct
90 Correct 16 ms 1104 KB Output is correct
91 Correct 13 ms 1108 KB Output is correct
92 Correct 18 ms 1104 KB Output is correct
93 Correct 21 ms 1104 KB Output is correct
94 Correct 12 ms 1116 KB Output is correct
95 Correct 11 ms 1104 KB Output is correct
96 Correct 13 ms 1116 KB Output is correct
97 Correct 6 ms 1120 KB Output is correct