답안 #936621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936621 2024-03-02T12:03:27 Z Ghetto 커다란 상품 (IOI17_prize) C++17
0 / 100
5 ms 444 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int n;

int v_sum;
int find_v_sum() {
	unordered_map<int, int> sum_freq;
	for (int i = 0; i < min(n, 1000); i++) {
		vector<int> res = ask(i);
		sum_freq[res[0] + res[1]]++;
	}

	for (pii sf : sum_freq)
		if (sf.second >= min(n / 2, 500)) return sf.first;
	assert(true == false); 
}

bool is_v(int res_sum) {
	return res_sum == v_sum;
}

vector<int> append(vector<int> v1, vector<int> v2) {
	v1.insert(v1.end(), v2.begin(), v2.end());
	return v1;
}

vector<int> find_non_vs(int lo, int hi, int l, int r) {
	// cout << "CALL " << lo << " " << hi << " " << l << " " << r << endl;
	if (lo > hi) return {}; 

	vector<int> ans, res;
	int l_mid = (lo + hi) / 2, r_mid = (lo + hi) / 2;
	while (r_mid <= hi) {
		res = ask(r_mid);
		if (is_v(res[0] + res[1])) break;
		ans.push_back(r_mid);
		r_mid++;
	}
	if (r_mid == hi + 1) return append(ans, find_non_vs(lo, l_mid - 1, l, r + r_mid - l_mid + 1));

	int l_size = res[0] - l - (r_mid - l_mid);
	int r_size = res[1] - r;
	// cout << "DETAILS " << l_mid << " " << r_mid << " " << l_size << " " << r_size << endl;
	assert(min(l_size, r_size) >= 0);	

	if (l_size == 0 && r_size == 0) return ans;
	else if (l_size == 0) return append(ans, find_non_vs(r_mid + 1, hi, l + r_mid - l_mid + 1, r));
	else if (r_size == 0) return append(ans, find_non_vs(lo, l_mid - 1, l, r + r_mid - l_mid + 1));
	else {
		vector<int> l_ans = find_non_vs(r_mid + 1, hi, l + r_mid - l_mid + 1, r);
		vector<int> r_ans = find_non_vs(r_mid + 1, hi, l + r_mid - l_mid + 1, r);
		return append(ans, append(l_ans, r_ans));
	}
}

int find_best(int tmp_n) {
	n = tmp_n;

	v_sum = find_v_sum();

	vector<int> non_vs = find_non_vs(0, n - 1, 0, 0);
	for (int non_v : non_vs) {
		vector<int> res = ask(non_v);
		if (res[0] + res[1] == 0) return non_v;
	}
	assert(true == false);
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 440 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 444 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -