Submission #136058

# Submission time Handle Problem Language Result Execution time Memory
136058 2019-07-24T16:49:54 Z JustasZ The Big Prize (IOI17_prize) C++14
0 / 100
101 ms 504 KB
#include "prize.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
/*vector<int> ask(int i)
{
	cout << "? " << i << endl;
	vector<int>a(2);
	cin >> a[0] >> a[1];
	return a;
}*/
int bl = 70;
int find_best(int n)
{
	vector<int>a, b;
	int mx = 0;
	for(int i = 0; i < min(n, 500); i++)
	{
		a = ask(i);
		if(a[0] + a[1] == 0)
			return i;
		mx = max(mx, a[0] + a[1]);
	}
	for(int i = 500; i < n; i += bl)
	{
		int j = min(i + bl - 1, n - 1);
		int p = i;
		a = ask(p);
		while(a[0] + a[1] != mx)
		{
			if(a[0] + a[1] == 0)
				return p;
			p++;
			if(p > j)
				break;
			a = ask(p);
		}
		a = ask(j);
		while(a[0] + a[1] != mx)
		{
			if(a[0] + a[1] == 0)
				return j;
			j--;
			if(j < p)
				break;
			a = ask(j);
		}
		if(p < j)
		{
			a = ask(p), b = ask(j);
			assert(a[0] + a[1] + b[0] + b[1] == 2 * mx);
			int between = b[0] - a[0];
			if(between != 0)
			{
				int it = p + 1;
				while(it < j && between > 0)
				{
					a = ask(it);
					if(a[0] + a[1] != mx)
					{
						between--;
						if(a[0] + a[1] == 0)
							return it;
					}
					else
					{
						int l = it, r = j - 1;
						while(l < r)
						{
							int mid = (l + r) / 2;
							b = ask(mid);
							if(b[0] + b[1] != mx)
								r = mid;
							else
							{
								if(b[0] > a[0])
									r = mid - 1;
								else
									l = mid + 1;
							} 
						}
						it = l;
						a = ask(it);
						--between;
						if(a[0] + a[1] == 0)
							return it;
					}
					++it;
				}
			}
		}
	}
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:105:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 25 ms 248 KB Output is correct
2 Correct 72 ms 316 KB Output is correct
3 Correct 32 ms 504 KB Output is correct
4 Incorrect 101 ms 248 KB Incorrect
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 248 KB Output is correct
2 Partially correct 77 ms 276 KB Partially correct - number of queries: 7432
3 Partially correct 36 ms 396 KB Partially correct - number of queries: 6196
4 Incorrect 83 ms 376 KB Incorrect
5 Halted 0 ms 0 KB -