Submission #67673

# Submission time Handle Problem Language Result Execution time Memory
67673 2018-08-15T08:26:33 Z zscoder The Big Prize (IOI17_prize) C++17
20 / 100
55 ms 3112 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

ii dp[442311];
int n;
int totalquery;
const int MX = 10000;
ii query(int x)
{
	if(x<0||x>=n) return mp(0,0);
	if(dp[x].fi>=0) return dp[x];
	totalquery++; //assert(totalquery<=MX);
	vector<int> a = ask(x);
	dp[x].fi=a[0]; dp[x].se=a[1]; return dp[x];
}

vi global;
vector<int> vec;
int newmax;

void solve(int l, int r)
{
	if(l>r) return ;
	//later optimize by using count 
	int mid=(l+r)>>1;
	ii cntl=query(vec[l]);
	assert(cntl.fi+cntl.se<=newmax);
	if(cntl.fi+cntl.se<newmax){global.pb(vec[l]); solve(l+1,r); return ;}
	ii cntr=query(vec[r]);
	assert(cntr.fi+cntr.se<=newmax);
	if(cntr.fi+cntr.se<newmax){global.pb(vec[r]); solve(l,r-1); return ;}
	ii tmp = query(vec[mid]);
	assert(tmp.fi+tmp.se<=newmax);
	if(tmp.fi+tmp.se<newmax)
	{
		global.pb(vec[mid]);
		solve(l,mid-1); solve(mid+1,r);
		return ;
	}
	int cntleft = tmp.fi-cntl.fi;
	int cntright = tmp.se-cntr.se;
	if(cntleft) solve(l,mid);
	if(cntright) solve(mid,r);
}

int find_best(int _n) 
{
	n=_n;
	for(int i=0;i<n;i++) {dp[i]=mp(-1,-1);vec.pb(i);}
	while(vec.size()>1)
	{
		global.clear(); int C=0; int cr=int(vec.size());
		while(cr>1)
		{
			C+=int(sqrt(cr))+10; cr=int(sqrt(cr));
		}
		C=min(C,int(vec.size()));
		newmax=0;
		for(int i=0;i<C;i++) 
		{
			//cerr<<"QUERY : "<<query(vec[i]).fi<<' '<<query(vec[i]).se<<'\n';
			newmax=max(newmax,query(vec[i]).fi+query(vec[i]).se);
		}
		for(int i=0;i<C;i++)
		{
			if(query(vec[i]).fi+query(vec[i]).se<newmax) global.pb(i);
		}
		//cerr<<"NEWMAX : "<<newmax<<'\n';
		solve(C,int(vec.size())-1);
		//cerr<<"TOTAL NUMBER OF QUERIES : "<<totalquery<<'\n';
		vec=global; sort(vec.begin(),vec.end()); vec.erase(unique(vec.begin(),vec.end()),vec.end());
		/*
		for(int x:vec)
		{
			cerr<<x<<' ';
		}
		cerr<<'\n';
		*/
	}
	return vec[0];
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2796 KB Output is correct
2 Correct 7 ms 2796 KB Output is correct
3 Correct 10 ms 2920 KB Output is correct
4 Correct 55 ms 2920 KB Output is correct
5 Correct 12 ms 2920 KB Output is correct
6 Correct 11 ms 2956 KB Output is correct
7 Correct 13 ms 2956 KB Output is correct
8 Correct 12 ms 2956 KB Output is correct
9 Correct 9 ms 3112 KB Output is correct
10 Correct 12 ms 3112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3112 KB Output is correct
2 Correct 9 ms 3112 KB Output is correct
3 Correct 11 ms 3112 KB Output is correct
4 Correct 12 ms 3112 KB Output is correct
5 Correct 35 ms 3112 KB Output is correct
6 Correct 9 ms 3112 KB Output is correct
7 Correct 12 ms 3112 KB Output is correct
8 Correct 12 ms 3112 KB Output is correct
9 Correct 8 ms 3112 KB Output is correct
10 Correct 13 ms 3112 KB Output is correct
11 Incorrect 17 ms 3112 KB answer is not correct
12 Halted 0 ms 0 KB -