Submission #425968

# Submission time Handle Problem Language Result Execution time Memory
425968 2021-06-13T12:37:09 Z Tangent The Big Prize (IOI17_prize) C++17
0 / 100
1000 ms 284 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;
		auto cand = memo.lower_bound(lo);
		if (cand != memo.end() && cand->first <= hi) {
			med = cand->first;
		}
		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 264 KB Output is correct
2 Correct 1 ms 280 KB Output is correct
3 Correct 1 ms 264 KB Output is correct
4 Correct 2 ms 284 KB Output is correct
5 Correct 1 ms 268 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 272 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Execution timed out 3067 ms 200 KB Time limit exceeded
# 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 200 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 Execution timed out 3037 ms 200 KB Time limit exceeded
11 Halted 0 ms 0 KB -