Submission #425879

# Submission time Handle Problem Language Result Execution time Memory
425879 2021-06-13T12:09:01 Z Tangent The Big Prize (IOI17_prize) C++17
20 / 100
102 ms 972 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;
	while (b == a) {
		b = rand() % n;
	}
	auto res1 = ask2(a), res2 = ask2(b);
	if (!res1.first && !res1.second) {
		return a;
	}
	if (!res2.first && !res2.second) {
		return b;
	}
	int expcount = max(res1.first + res1.second, res2.first + res2.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) {
			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 284 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 284 KB Output is correct
5 Correct 1 ms 284 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 284 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 288 KB Output is correct
8 Correct 1 ms 260 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 2 ms 296 KB Output is correct
12 Correct 3 ms 300 KB Output is correct
13 Correct 7 ms 288 KB Output is correct
14 Correct 13 ms 320 KB Output is correct
15 Correct 55 ms 416 KB Output is correct
16 Correct 60 ms 536 KB Output is correct
17 Correct 40 ms 448 KB Output is correct
18 Correct 33 ms 448 KB Output is correct
19 Correct 30 ms 400 KB Output is correct
20 Correct 24 ms 396 KB Output is correct
21 Correct 30 ms 420 KB Output is correct
22 Correct 49 ms 448 KB Output is correct
23 Correct 2 ms 276 KB Output is correct
24 Correct 5 ms 200 KB Output is correct
25 Correct 27 ms 412 KB Output is correct
26 Correct 20 ms 500 KB Output is correct
27 Correct 3 ms 276 KB Output is correct
28 Correct 54 ms 408 KB Output is correct
29 Correct 44 ms 400 KB Output is correct
30 Correct 50 ms 448 KB Output is correct
31 Correct 34 ms 320 KB Output is correct
32 Correct 6 ms 284 KB Output is correct
33 Correct 1 ms 200 KB Output is correct
34 Correct 24 ms 532 KB Output is correct
35 Correct 3 ms 276 KB Output is correct
36 Correct 44 ms 556 KB Output is correct
37 Correct 6 ms 200 KB Output is correct
38 Correct 2 ms 200 KB Output is correct
39 Correct 63 ms 532 KB Output is correct
40 Correct 44 ms 404 KB Output is correct
41 Correct 32 ms 408 KB Output is correct
42 Correct 46 ms 468 KB Output is correct
43 Correct 22 ms 596 KB Output is correct
44 Correct 58 ms 480 KB Output is correct
45 Correct 53 ms 520 KB Output is correct
46 Correct 24 ms 540 KB Output is correct
47 Correct 60 ms 424 KB Output is correct
48 Correct 31 ms 404 KB Output is correct
49 Correct 28 ms 404 KB Output is correct
50 Correct 52 ms 532 KB Output is correct
51 Correct 49 ms 452 KB Output is correct
52 Correct 54 ms 576 KB Output is correct
53 Correct 3 ms 200 KB Output is correct
54 Correct 52 ms 488 KB Output is correct
55 Correct 44 ms 448 KB Output is correct
56 Correct 63 ms 640 KB Output is correct
57 Correct 55 ms 472 KB Output is correct
58 Correct 41 ms 532 KB Output is correct
59 Correct 22 ms 628 KB Output is correct
60 Correct 46 ms 448 KB Output is correct
61 Correct 2 ms 260 KB Output is correct
62 Correct 2 ms 280 KB Output is correct
63 Correct 1 ms 284 KB Output is correct
64 Correct 1 ms 280 KB Output is correct
65 Correct 2 ms 288 KB Output is correct
66 Correct 4 ms 280 KB Output is correct
67 Correct 6 ms 200 KB Output is correct
68 Correct 2 ms 200 KB Output is correct
69 Correct 6 ms 200 KB Output is correct
70 Correct 2 ms 308 KB Output is correct
71 Correct 83 ms 576 KB Output is correct
72 Correct 5 ms 200 KB Output is correct
73 Correct 70 ms 532 KB Output is correct
74 Correct 68 ms 484 KB Output is correct
75 Correct 2 ms 280 KB Output is correct
76 Correct 63 ms 440 KB Output is correct
77 Correct 42 ms 448 KB Output is correct
78 Correct 7 ms 200 KB Output is correct
79 Correct 20 ms 308 KB Output is correct
80 Correct 39 ms 468 KB Output is correct
81 Correct 51 ms 512 KB Output is correct
82 Correct 44 ms 492 KB Output is correct
83 Correct 2 ms 200 KB Output is correct
84 Correct 51 ms 516 KB Output is correct
85 Correct 38 ms 556 KB Output is correct
86 Incorrect 102 ms 972 KB Incorrect
87 Halted 0 ms 0 KB -