Submission #117962

# Submission time Handle Problem Language Result Execution time Memory
117962 2019-06-17T15:11:33 Z tinjyu The Big Prize (IOI17_prize) C++14
0 / 100
6 ms 3608 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int m,ball=0,a[200005][2],ans=-1;
int find(int x)
{
	if(a[x][0]==-1)
	{
		std::vector<int> res = ask(x);
		a[x][0]=res[0];
		a[x][1]=res[1];
	}
	return 0;
}
int solve(int s,int e){
	//cout<<s<<" "<<e<<endl;
	if(s>=e-1)return 0;
	if(ans!=-1)return 0;
	int ne,ns;
	if((s+e)%2==0)ne=(s+e)/2,ns=(s+e)/2;
	else ne=(s+e)/2+1,ns=(s+e)/2+1;
	while(ns<e)
	{
		find(ns);
		if(a[ns][0]+a[ns][1]==0)
		{
			ans=ns;
			return 0;
		}
		if(a[ns][0]+a[ns][1]!=ball)ns++;
		else break;
	}
	while(s<ne)
	{
		find(ne);
		if(a[ne][0]+a[ne][1]==0)
		{
			ans=ne;
			break;
		}
		if(a[ne][0]+a[ne][1]!=ball)ne--;
		else break;
	}
	//cout<<ne<<" "<<ns<<endl;
	if(a[s][0]!=a[ne][0] )solve(s,ne);
	if(a[ns][0]!=a[e][0] )solve(ns,e);
}
int find_best(int n) {
	for(int i=0;i<n;i++)
	{
		a[i][0]=-1;
		a[i][1]=-1;
	}
	for(int i = 0; i < 200; i++) {
		int as=rand()*rand()%n;
		find(i);
		//cout<<a[i][0]<<" "<<a[i][1]<<endl;
		if(a[as][0]+a[as][1]==0)
		{
			ans=as;
			break;
		}
		if(a[as][0] + a[as][1] > ball)
		{
			m=as;
			ball=a[as][0]+a[as][1];
		}
	}
	if(ans!=-1)return ans;
 
//	cout<<m<<endl;
	int start=0,end=n-1;
	while(true)
	{
		find(start);
		if(a[start][0]+a[start][1]==0)ans=start;
		if(a[start][0]+a[start][1]!=ball)start++;
		else break;
	}
	while(true)
	{
		find(end);
		if(a[end][0]+a[end][1]==0)ans=end;
		if(a[end][0]+a[end][1]!=ball)end--;
		else break;
	}
	if(ans!=-1)return ans;
	//cout<<start<<" "<<end<<endl;
	solve(start,m);
	solve(m,end);
	return ans;
}

Compilation message

prize.cpp: In function 'int solve(int, int)':
prize.cpp:47:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 3608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 3512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -