답안 #1048253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048253 2024-08-08T06:02:37 Z Gromp15 커다란 상품 (IOI17_prize) C++17
0 / 100
5 ms 2904 KB
#include "prize.h"
#include <bits/stdc++.h>
#define ar array
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;

const int N = 500;

int find_best(int n) {
	map<int, vector<int>> mp;
	auto _ask = [&](int x) {
		if (mp.count(x)) return mp[x];
		auto res = ask(x);
		if (res[0] + res[1] == 0) return res;
		return mp[x] = res;
	};
	int mx = 0;
	for (int i = 0; i < min(n, N); i++) {
		auto res = _ask(i);
		mx = max(mx, res[0] + res[1]);
		if (res[0] + res[1] == 0) return i;
	}
	auto solve = [&](auto&& s, vector<int> ask, int ml, int mr) -> void {
		if (ml > mr || ask.empty()) return;
		int want = (ml + mr) / 2;
		int tl = 0, tr = sz(ask) - 1, ans = -1;
		while (tl <= tr) {
			int mid = (tl + tr) / 2;
			auto res = _ask(mid);
			if (res[0] + res[1] < mx) {
				ask.erase(ask.begin() + mid);
				tr--; continue;
			}
			else {
				if (res[0] >= want) ans = mid, tr = mid - 1;
				else tl = mid + 1;
			}
		}
		if (!~ans) return;
		if (ans - 2 >= 0) {
			s(s, vector<int>(ask.begin(), ask.begin() + ans - 1), ml, want - 1);
		}
		if (ans + 1 < sz(ask)) {
			s(s, vector<int>(ask.begin() + ans + 1, ask.end()), want + 1, mr);
		}
	};
	vector<int> idx(n);
	iota(all(idx), 0);
	solve(solve, idx, 1, mx);
	assert(0);
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 2904 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 2648 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -