제출 #410550

#제출 시각아이디문제언어결과실행 시간메모리
410550dreezyThe Big Prize (IOI17_prize)C++17
20 / 100
3024 ms11336 KiB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

/*********************************************************************************************************************/
const int maxn = 2e5 + 5;
int find_best(int n) {
	
	int curtotal = -1;
	vector<vector<int>> asked(maxn, {-1,-1});
	for(int i =0; i<min(500, n); i++){
		vector<int> res= ask(i);
		asked[i] = res;
		if( !res[0] && !res[1]) return i;
		curtotal = max(curtotal,res[0] +res[1]);
	}

	
	int left = 0, right = n-1;
	int target =1;
	int cnt =0;
	while(true){
		int ind = (left +right) /2 ;
		//cout << left <<", "<<ind<<", "<<right<<": "<<target<<" "<<curtotal<<endl;
		vector<int> res;
		if((asked[ind] == vector<int>({-1,-1}))){
			res = ask(ind);
			asked[ind] = res;
		}
		else{
			res = asked[ind];
		}
		
		if(res[0] + res[1] == 0)
			return ind;
		if(res[0] + res[1] < curtotal){
			if((asked[ind-1] == vector<int>({-1,-1})) ){
				res = ask(ind-1);
				asked[ind-1] = res;
			}
			else{
				res = asked[ind-1];
			}
			ind--;
			while(res[0]+ res[1] < curtotal){
				if(res[0] + res[1] == 0)
					return ind;
				--ind;
				
				if(ind <0){
					break;
				}
				
				if( (asked[ind] == vector<int>({-1,-1})) ){
					res = ask(ind);
					asked[ind] = res;
				}
				else{
					res = asked[ind];
				}
					
				
			}
			
			if(res[0] + res[1] == curtotal){
				if(res[0] <= target){
					target = target +1;
					left = ind +1;
					right = n-1;
				}
				else{
					target = target +1;
					right = ind - 1;
				}
			}
			
			
		}
		
		if(res[0] < target){
			left = ind +1;
		}
		else{
			right = ind - 1;
		}
		//cnt++;
		//if(cnt >=20) break;
	}
	
	return 0;
}


/*********************************************************************************************************************/

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

prize.cpp: In function 'int find_best(int)':
prize.cpp:21:6: warning: unused variable 'cnt' [-Wunused-variable]
   21 |  int cnt =0;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...