답안 #936645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936645 2024-03-02T12:38:58 Z Ghetto 커다란 상품 (IOI17_prize) C++17
0 / 100
7 ms 436 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;
}

int find_one(int lo, int hi, int l, int r) { // -1 if none
	// cout << "CALL " << lo << " " << hi << " " << l << " " << r << endl;
	if (lo > hi) return {}; 

	vector<int> 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;
		if (res[0] + res[1] == 0) return r_mid;
		r_mid++;
	}
	if (r_mid == hi + 1) return find_one(lo, l_mid - 1, l, r + r_mid - l_mid);

	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 -1;
	else if (l_size == 0) find_one(r_mid + 1, hi, l + r_mid - l_mid, r);
	else if (r_size == 0) return find_one(lo, l_mid - 1, l, r + r_mid - l_mid);
	else return max(find_one(lo, l_mid - 1, l, r + r_size + r_mid - l_mid), find_one(r_mid + 1, hi, l + l_size + r_mid - l_mid, r)); 
}

int find_best(int tmp_n) {
	n = tmp_n;

	v_sum = find_v_sum();

	int ans = find_one(0, n - 1, 0, 0);
	return ans;
}

Compilation message

prize.cpp: In function 'int find_one(int, int, int, int)':
prize.cpp:34:14: warning: control reaches end of non-void function [-Wreturn-type]
   34 |  vector<int> res;
      |              ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 436 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 436 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -