답안 #64436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64436 2018-08-04T13:15:57 Z nvmdava 커다란 상품 (IOI17_prize) C++17
0 / 100
5 ms 616 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;


vector<int> v, s;
map<int, bool> in;
map<int, vector<int> > ans;
int find(int l, int r){
	if(ans[l][0] == ans[r][0]){
		return 0;
	}
	int m = (l + r) >> 1, L = m, R = m + 1;
	while(l < L){
		ans[L] =ask(L);
		if(ans[L][0] + ans[L][1] == s.back()){
			break;
		}
		if(ans[L][0] + ans[L][1] == 0){
			return L;
		}
		L--;
	}
	while(r > R){
		ans[R] =ask(R);
		if(ans[R][0] + ans[R][1] == s.back()){
			break;
		}
		if(ans[R][0] + ans[R][1] == 0){
			return R;
		}
		R++;
	}
	return max(find(l, L), find(r, R));
}

int find_best(int n) {
	
	
	for(int i = 0; i < 35; i++){
		ans[i] = ask(i);
		if(in[ans[i][0] + ans[i][1]] == 0){
			if(ans[i][0] + ans[i][1] == 0){
				return i;
			}
			in[ans[i][0] + ans[i][1]] = 1;
			s.push_back(ans[i][0] + ans[i][1]);
		}
	}
	
	sort(s.begin(),s.end());
	
	int l = 0, r = n - 1;
	while(true){
		if(ans[l][0] + ans[l][1] == s.back()){
			break;
		}
		l++;
	}
	while(true){
		
		ans[r] = ask(r);
		
		if(ans[r][0] + ans[r][1] == s.back()){
			break;
		}
		if(ans[r][0] + ans[r][1] == 0){
			return r;
		}
		r--;
	}
	
	return find(l, r);
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -