Submission #425944

# Submission time Handle Problem Language Result Execution time Memory
425944 2021-06-13T12:29:55 Z Tangent The Big Prize (IOI17_prize) C++17
20 / 100
95 ms 880 KB
#include "prize.h"
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;

#define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()

map<int, pii> memo;
pii ask2(int i) {
	if (memo.find(i) == memo.end()) {
		auto res = ask(i);
		memo[i] = {res[0], res[1]};
	}
	return memo[i];
}

int find_best(int n) {
	if (n <= 5000) {
		rep(i, n) {
			auto res = ask2(i);
			if (!res.first && !res.second) {
				return i;
			}
		}
	}
	int a = n / 2, b = rand() % n, c = rand() % n;
	while (b == a) {
		b = rand() % n;
	}
	while (c == a || c == b) {
		c = rand() % n;
	}
	auto res1 = ask2(a), res2 = ask2(b), res3 = ask2(c);
	if (!res1.first && !res1.second) {
		return a;
	}
	if (!res2.first && !res2.second) {
		return b;
	}
	if (!res3.first && !res3.second) {
		return c;
	}
	int expcount = max(max(res1.first + res1.second, res2.first + res2.second), res3.first + res3.second);
	
	int found = 0;
	while (res1.first + res1.second != expcount) {
		a++;
		found++;
		res1 = ask2(a);
		if (!res1.first && !res1.second) {
			return a;
		}
	}
	deque<tuple<int, int, int, int, int>> segs = {{0, n / 2 - 1, res1.first - found, 0, found + res1.second}, {a + 1, n - 1, res1.second, res1.first, 0}};
	while (!segs.empty()) {
		int lo, hi, cnt, tol, tor, l, r;
		tie(lo, hi, cnt, tol, tor) = segs.front();
		segs.pop_front();
		
		int med = (lo + hi) / 2;
		tie(l, r) = ask2(med);
		if (!l && !r) {
			return med;
		}
		int found2 = 0;
		while (l + r != expcount && med < hi) {
			med++;
			found2++;
			tie(l, r) = ask2(med);
			if (!l && !r) {
				return med;
			}
		}
		if (l + r > expcount) {
			expcount = l + r;
			segs.clear();
			segs = {{0, med - 1, l, 0, r}};
			segs = {{med + 1, n - 1, r, l, 0}};
			continue;
		}
		if (l + r != expcount) {
			if (cnt - found2 > 0) {
				segs.emplace_back(lo, (lo + hi) / 2 - 1, cnt - found2, tol, tor + found2);
			}
		} else {
			if (l - found2 - tol > 0) {
				segs.emplace_back(lo, (lo + hi) / 2 - 1, l - found2 - tol, tol, found2 + r);
			}
			if (r - tor > 0) {
				segs.emplace_back(med + 1, hi, r - tor, l, tor);
			}

		}
	}
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 284 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 288 KB Output is correct
2 Correct 2 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 280 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 6 ms 276 KB Output is correct
12 Correct 3 ms 300 KB Output is correct
13 Correct 6 ms 200 KB Output is correct
14 Correct 9 ms 328 KB Output is correct
15 Correct 34 ms 492 KB Output is correct
16 Correct 41 ms 468 KB Output is correct
17 Correct 63 ms 448 KB Output is correct
18 Correct 48 ms 448 KB Output is correct
19 Correct 22 ms 652 KB Output is correct
20 Correct 26 ms 448 KB Output is correct
21 Correct 40 ms 380 KB Output is correct
22 Correct 34 ms 416 KB Output is correct
23 Correct 3 ms 276 KB Output is correct
24 Correct 5 ms 200 KB Output is correct
25 Correct 40 ms 448 KB Output is correct
26 Correct 55 ms 416 KB Output is correct
27 Correct 2 ms 200 KB Output is correct
28 Correct 56 ms 560 KB Output is correct
29 Correct 46 ms 448 KB Output is correct
30 Correct 50 ms 392 KB Output is correct
31 Correct 19 ms 300 KB Output is correct
32 Correct 6 ms 284 KB Output is correct
33 Correct 1 ms 200 KB Output is correct
34 Correct 32 ms 436 KB Output is correct
35 Correct 3 ms 272 KB Output is correct
36 Correct 50 ms 524 KB Output is correct
37 Correct 3 ms 328 KB Output is correct
38 Correct 3 ms 284 KB Output is correct
39 Correct 65 ms 576 KB Output is correct
40 Correct 47 ms 492 KB Output is correct
41 Correct 42 ms 448 KB Output is correct
42 Correct 38 ms 456 KB Output is correct
43 Correct 35 ms 640 KB Output is correct
44 Correct 43 ms 528 KB Output is correct
45 Correct 64 ms 400 KB Output is correct
46 Correct 59 ms 488 KB Output is correct
47 Correct 60 ms 448 KB Output is correct
48 Correct 35 ms 324 KB Output is correct
49 Correct 35 ms 392 KB Output is correct
50 Correct 64 ms 452 KB Output is correct
51 Correct 24 ms 544 KB Output is correct
52 Correct 63 ms 576 KB Output is correct
53 Correct 3 ms 200 KB Output is correct
54 Correct 51 ms 448 KB Output is correct
55 Correct 58 ms 452 KB Output is correct
56 Correct 64 ms 576 KB Output is correct
57 Correct 41 ms 664 KB Output is correct
58 Correct 42 ms 448 KB Output is correct
59 Correct 62 ms 448 KB Output is correct
60 Correct 42 ms 484 KB Output is correct
61 Correct 2 ms 272 KB Output is correct
62 Correct 2 ms 272 KB Output is correct
63 Correct 2 ms 200 KB Output is correct
64 Correct 2 ms 200 KB Output is correct
65 Correct 1 ms 200 KB Output is correct
66 Correct 3 ms 292 KB Output is correct
67 Correct 3 ms 344 KB Output is correct
68 Correct 1 ms 280 KB Output is correct
69 Correct 4 ms 276 KB Output is correct
70 Correct 2 ms 344 KB Output is correct
71 Correct 45 ms 556 KB Output is correct
72 Correct 8 ms 292 KB Output is correct
73 Correct 47 ms 448 KB Output is correct
74 Correct 79 ms 576 KB Output is correct
75 Correct 3 ms 200 KB Output is correct
76 Correct 64 ms 460 KB Output is correct
77 Correct 63 ms 448 KB Output is correct
78 Correct 7 ms 200 KB Output is correct
79 Correct 30 ms 408 KB Output is correct
80 Correct 65 ms 576 KB Output is correct
81 Correct 40 ms 448 KB Output is correct
82 Correct 67 ms 448 KB Output is correct
83 Correct 3 ms 200 KB Output is correct
84 Correct 51 ms 448 KB Output is correct
85 Correct 48 ms 444 KB Output is correct
86 Correct 19 ms 420 KB Output is correct
87 Partially correct 92 ms 552 KB Partially correct - number of queries: 6493
88 Correct 18 ms 328 KB Output is correct
89 Correct 17 ms 328 KB Output is correct
90 Incorrect 95 ms 880 KB Incorrect
91 Halted 0 ms 0 KB -