Submission #118986

#TimeUsernameProblemLanguageResultExecution timeMemory
118986Mahdi_JfriKoala Game (APIO17_koala)C++14
61 / 100
88 ms504 KiB
#include "koala.h"
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back

const int maxn = 1e2 + 20;

int b[maxn] , r[maxn] , ind[maxn];
bool can[maxn];

int minValue(int n, int w)
{
	memset(b , 0 , sizeof b);
	b[0] = 1;

	playRound(b , r);
	if(r[0] != 2)
		return 0;

	for(int i = 1; i < n - 1; i++)
		if(!r[i])
			return i;
}

int maxValue(int n, int w)
{
	for(int i = 0; i < n; i++)
		can[i] = 1;

	int rem = n;
	while(rem > 1)
	{
		for(int i = 0; i < n; i++)
		{
			if(can[i])
				b[i] = w / rem;
			else
				b[i] = 0;
		}
		playRound(b , r);

		for(int i = 0; i < n; i++)
			if(can[i] && r[i] <= b[i])
				can[i] = 0 , rem--;
	}

	for(int i = 0; i < n; i++)
		if(can[i])
			return i;
}

bool f;
bool cmp(int p1 , int p2)
{
	int l = 1 , rx = 14;
	while(1)
	{
		memset(b , 0 , sizeof b);

		int m = (l + rx) / 2;
		b[p1] = b[p2] = m;
		if(f)
			for(int i = 0; i < 100; i++)
				b[i]++;
		playRound(b , r);

		if(b[p1] < r[p1] && b[p2] < r[p2])
		{
			l = m + 1;
			continue;
		}
		if(b[p1] < r[p1] && b[p2] >= r[p2])
			return 0;
		if(b[p1] >= r[p1] && b[p2] < r[p2])
			return 1;
		rx = m - 1;
	}
}

int greaterValue(int n, int w)
{
	return cmp(0 , 1);
}

void allValues(int n, int w, int *p)
{
	if (w == 2*n)
	{
		for(int i = 0; i < n; i++)
			ind[i] = i;
		f = 1;
		sort(ind , ind + n , cmp);
		for(int i = 0; i < n; i++)
			p[ind[i]] = i + 1;
		sort(ind , ind + n , cmp);
	}
	else
	{
		for(int i = 0; i < n; i++)
			ind[i] = i;
		sort(ind , ind + n , cmp);
		for(int i = 0; i < n; i++)
			p[ind[i]] = i + 1;
	}
}


Compilation message (stderr)

koala.cpp: In function 'int minValue(int, int)':
koala.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...