Submission #299915

#TimeUsernameProblemLanguageResultExecution timeMemory
299915pacha2880The Big Prize (IOI17_prize)C++17
0 / 100
93 ms256 KiB
#include <bits/stdc++.h>
#include <prize.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define md(a, b)		((a) % b + b) % b
#define mod(a)			md(a, MOD)
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define forn(i, n)			for(int i = 0; i < n; i++)
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
//int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef long long 		ll;
typedef long double ld;	
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1); 

int find_best(int n)
{
	int lo = 0, hi = n - 1, mid, res;
	pair<int, int> maxi{0,0};
	fore(i, 0, min(700, n))
	{
		auto ar = ask(i);
		if(ar[0] + ar[1] == 0)
			return i;
		maxi = max(maxi, mp(ar[0] + ar[1], i));
	}
	int can = maxi.f, pos = maxi.s;
	while(true)
	{
		lo = pos + 1, hi = n - 1;
		while(lo <= hi)
		{
			mid = (lo + hi) / 2;
			auto ar = ask(mid);
			if(ar[0] + ar[1] != can)
				pos = mid, hi = mid - 1;
			else
				lo = mid + 1;
		}
		while(true)
		{
			auto ar = ask(pos);
			if(ar[0] + ar[1] == 0)
				return pos;
			if(ar[0] + ar[1] == can)
				break;
			pos++;
		}
	}
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2	

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:40:31: warning: unused variable 'res' [-Wunused-variable]
   40 |  int lo = 0, hi = n - 1, mid, res;
      |                               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...