제출 #592604

#제출 시각아이디문제언어결과실행 시간메모리
592604hltk커다란 상품 (IOI17_prize)C++17
0 / 100
3050 ms400 KiB
#include "prize.h"

#include <bits/stdc++.h>

using namespace std;

using pii = pair<int, int>;

map<int, pii> C;

pii m_ask(int i) {
	if (C.count(i)) return C[i];
	auto a = ask(i);
	return C[i] = {a[0], a[1]};
}


// 1, 2, 5, 26, 677

int find_best(int n) {
	if (n <= 1000) {
		for (int i = 0; i < n; ++i) {
			auto [a, b] = m_ask(i);
			if (a + b == 0) {
				return i;
			}
		}
		throw;
	}
	int t = 0;
	for (int i = 0; i < 800; ++i) {
		auto [a, b] = m_ask(i);
		t = max(t, a + b);
	}
	auto check = [&](int i) {
		auto [a, b] = m_ask(i);
		return a + b != t;
	};
	for (int i = 0; i < n; ++i) {
		if (check(i)) {
			auto [a, b] = m_ask(i);
			if (a + b == 0) return i;
		} else {
			auto same = [&](int j) {
				return !check(j) && m_ask(j).second == m_ask(i).second;
			};
			for (int st = i; st < n; st += 400) {
				int ed = min(st + 400, n - 1);
				if (same(ed)) continue;
				int l = st, r = ed - 1;
				while (l < r) {
					int m = (l + r) / 2;
					if (!same(m)) r = m;
					else l = m + 1;
				}
				i = l - 1;
				break;
			}
		}
	}
}

컴파일 시 표준 에러 (stderr) 메시지

prize.cpp: In function 'int find_best(int)':
prize.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
   61 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...