Submission #43136

# Submission time Handle Problem Language Result Execution time Memory
43136 2018-03-09T10:18:55 Z RayaBurong25_1 The Big Prize (IOI17_prize) C++14
0 / 100
2 ms 4368 KB
#include "prize.h"
#include <stdio.h>
#include <vector>
#include <algorithm>
int L[200005], R[200005];
int V[200005];
int min(int a, int b)
{
	return (a < b)?a:b;
}
int max(int a, int b)
{
	return (a > b)?a:b;
}
int find_best(int n) {
	int i;
	for (i = 0; i < n; i++)
		L[i] = -1;
	int mn, md, mx;
	//first sig
	std::vector<int> r;
	r = ask(0);
	L[0] = r[0];
	R[0] = r[1];
	if (R[0] == 0)
		return 0;
	r = ask(n - 1);
	L[n - 1] = r[0];
	R[n - 1] = r[1];
	if (L[n - 1] == 0)
		return n - 1;
	r = ask((n - 1)/2);
	L[(n - 1)/2] = r[0];
	R[(n - 1)/2] = r[1];
	if (L[(n - 1)/2] == 0)
		return (n - 1)/2;
	r = ask((n - 1)/2 + 1);
	L[(n - 1)/2 + 1] = r[0];
	R[(n - 1)/2 + 1] = r[1];
	if (L[(n - 1)/2 + 1] == 0)
		return (n - 1)/2 + 1;
	int sigl = 0, sigm1 = (n - 1)/2, sigm2 = (n - 1)/2 + 1, sigr = n - 1;
	while (sigl < sigm1 || sigm2 < sigr)
	{
		if (sigm2 < sigr)
		{
			mn = sigm2;
			mx = sigr;
			while (mx != mn)
			{
				if (mx - mn == 1)
				{
					sigr = mn;
					break;
				}
				md = (mn + mx)/2;
				if (L[md] == -1)
				{
					r = ask(md);
					L[md] = r[0];
					R[md] = r[1];
				}
				if (L[md] == L[sigr] && R[md] == R[sigr])
					mx = md;
				else
					mn = md;
			}
			if (L[sigr] == -1)
			{
				r = ask(sigr);
				L[sigr] = r[0];
				R[sigr] = r[1];
			}
			if (L[sigr] == 0 && R[sigr] == 0)
				return sigr;
		}
		// printf("sigl %d sigr %d\n", sigl, sigr);
		if (sigl < sigm1)
		{
			mn = sigl;
			mx = sigm1;
			while (mx != mn)
			{
				if (mx - mn == 1)
				{
					sigl = mx;
					break;
				}
				md = (mn + mx)/2;
				if (L[md] == -1)
				{
					r = ask(md);
					L[md] = r[0];
					R[md] = r[1];
				}
				if (L[md] == L[sigl] && R[md] == R[sigl])
					mn = md;
				else
					mx = md;
			}
			if (L[sigl] == -1)
			{
				r = ask(sigl);
				L[sigl] = r[0];
				R[sigl] = r[1];
			}
			if (L[sigl] == 0 && R[sigl] == 0)
				return sigl;
		}
		//
		if (sigl < sigm1)
		{
			mn = sigl;
			mx = sigm1;
			while (mx != mn)
			{
				if (mx - mn == 1)
				{
					sigm1 = mn;
					break;
				}
				md = (mn + mx)/2;
				if (L[md] == -1)
				{
					r = ask(md);
					L[md] = r[0];
					R[md] = r[1];
				}
				if (L[md] == L[sigm1] && R[md] == R[sigm1])
					mx = md;
				else
					mn = md;
			}
			if (L[sigm1] == -1)
			{
				r = ask(sigm1);
				L[sigm1] = r[0];
				R[sigm1] = r[1];
			}
			if (L[sigm1] == 0 && R[sigm1] == 0)
				return sigm1;
		}
		// printf("sigl %d sigr %d\n", sigl, sigr);
		if (sigm2 < sigr)
		{
			mn = sigm2;
			mx = sigr;
			while (mx != mn)
			{
				if (mx - mn == 1)
				{
					sigm2 = mx;
					break;
				}
				md = (mn + mx)/2;
				if (L[md] == -1)
				{
					r = ask(md);
					L[md] = r[0];
					R[md] = r[1];
				}
				if (L[md] == L[sigm2] && R[md] == R[sigm2])
					mn = md;
				else
					mx = md;
			}
			if (L[sigm2] == -1)
			{
				r = ask(sigm2);
				L[sigm2] = r[0];
				R[sigm2] = r[1];
			}
			if (L[sigm2] == 0 && R[sigm2] == 0)
				return sigm2;
		}
	}
	if (sigl == sigr)
		return sigl;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:179:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4368 KB Output is correct
2 Incorrect 1 ms 4368 KB answer is not correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4368 KB Output is correct
2 Incorrect 1 ms 4368 KB answer is not correct
3 Halted 0 ms 0 KB -