제출 #285174

#제출 시각아이디문제언어결과실행 시간메모리
285174mohammad커다란 상품 (IOI17_prize)C++14
98.18 / 100
66 ms392 KiB
#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
 
#define endl "\n"
// #define int long long

typedef long long ll ;
const ll ooo = 1e14 ;
const ll oo = 2e9 ;
const double PI = acos(-1) ;
const ll M = 1e9 + 7  ;
const int N = 10000010  ;

int binary(int lo , int hi , vector<int> l , vector<int> r){
	if(lo > hi) return -1;
	int md = (lo + hi) / 2;
	vector<int> res = ask(md);
	if(res[0] + res[1] == 0) return md;
	int ans = -1;
	int ra = rand() % 2;
	if(ra){
		if(res[1] > 0 && res != l) ans = binary(md+1 , hi , l , res);
		if(ans == -1 && res[0] > 0 && res != r) ans = binary(lo , md - 1 , res , r);
	}else {
		if( res[0] > 0 && res != r) ans = binary(lo , md - 1 , res , r);
		if(ans == -1 && res[1] > 0 && res != l) ans = binary(md+1 , hi , l , res);
	}
	return ans ;
}

int find_best(int n) {
	srand (time(NULL));
	vector<int> x(2 , -1);
	return binary(0 , n - 1 , x , x);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...