Submission #299926

#TimeUsernameProblemLanguageResultExecution timeMemory
299926pacha2880The Big Prize (IOI17_prize)C++17
20 / 100
95 ms384 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 ar[] = {4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 3, 1, 4, 4, 4, 4, 2, 4, 4, 4, 3};
int q;
vector<int> ask(int i)
{
	q++;
	vector<int> res(2, 0);
	fore(j, 0, i)
		res[0] += ar[j] < ar[i];
	fore(j, i + 1, 64)
		res[1] += ar[j] < ar[i];
	return res;
}
int find_best(int n);
int main()
{
	q = 0;
	cout<<find_best(64)<<'\n';
	cout<<q<<'\n';
	return 0;
}*/
int find_best(int n)
{
	int lo = 0, hi = n - 1, mid, res;
	pair<int, pair<int, int>> maxi{0,{0, 0}};
	fore(i, 0, 1)
	{
		auto ar = ask(i);
		if(ar[0] + ar[1] == 0)
			return i;
		maxi = max(maxi, mp(ar[0] + ar[1], mp(i, ar[0])));
	}
	int can = maxi.f, pos = maxi.s.f, le = maxi.s.s;
	//cout<<le<<'\n';
	while(true)
	{
		//cout<<"sdac       "<<pos<<'\n';
		lo = pos + 1, hi = n - 1;
		while(lo <= hi)
		{
			mid = (lo + hi) / 2;
			auto ar = ask(mid);
			//cout<<mid<<' '<<ar[0]<<' '<<ar[1]<<'\n';
			if(ar[0] + ar[1] != can)
				pos = mid, hi = mid - 1;
			else
			{
				if(ar[0] > le)
					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)
			{
				le = ar[0];
				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:60:31: warning: unused variable 'res' [-Wunused-variable]
   60 |  int lo = 0, hi = n - 1, mid, res;
      |                               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...