Submission #358443

# Submission time Handle Problem Language Result Execution time Memory
358443 2021-01-25T13:47:18 Z CaroLinda Koala Game (APIO17_koala) C++14
97 / 100
87 ms 520 KB
#include "koala.h"
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define ll long long
#define sz(x) (int)(x.size() )

using namespace std ;

int b[100] , r[100] ;

void clean() { for(int i = 0 ; i < 100 ; i++ ) b[i] = 0 ; }

int minValue(int N, int W) 
{
	clean() ;

	b[0] = 1 ;
	playRound(b, r) ;

	if(r[0] < 2 ) return 0 ;

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

int maxValue(int N, int W) 
{

	vector<int> v(N) ; iota(all(v),0) ;	
	vector<int> aux ;

	while( sz(v) > 1 )
	{
		clean() ;
		
		for(auto e : v ) b[e] = 100/sz(v) ;
	
		playRound(b, r) ;

		aux.clear() ;
		for(auto e : v ) 
			if( r[e] > b[e] ) aux.push_back(e) ;

		swap(v,aux) ;
	}

	return v[0] ;

}

int greaterValue(int N, int W) 
{
	clean() ;
	b[0] = b[1] = 5 ;

	playRound(b,r) ;

	if( (b[0] < r[0] ) != (b[1] < r[1] ) ) return (b[1] < r[1] ) ;

	if( b[0] < r[0] )
	{
		b[0] = b[1] = 7 ;
		playRound(b,r) ;

		if( (b[0] < r[0] ) != (b[1] < r[1] ) ) return (b[1] < r[1] ) ;

		b[0] = b[1] = 8 ;
		playRound(b,r) ;

		return (b[1] < r[1] ) ;

	}
	else
	{
		b[0] = b[1] = 2 ;
		playRound(b,r) ;
		
		if( (b[0] < r[0] ) != (b[1] < r[1] ) ) return (b[1] < r[1] ) ;
		if(b[0] < r[0] )
		{
			b[0] = b[1] = 3 ;
			playRound(b,r) ;
			return (b[1] < r[1] ) ;
		}
		else
		{
			b[0] = b[1] = 1 ;
			playRound(b,r) ;
			return (b[1] < r[1] ) ;
		}

	}

}

int p[100] ;

bool isLarger(int x , int y, int t = 100  )
{
	clean() ;

	b[x] = b[y] = t ;
	playRound(b,r) ;

	return (b[x] < r[x] ) ;
}

vector<pair<int,int> > forbidden = {make_pair(92,96), make_pair(87,91), make_pair(84,86),
make_pair(76,79), make_pair(66,69), make_pair(61,64),
make_pair(58,60), make_pair(51,54), make_pair(47,49),
make_pair(39,41), make_pair(36,38), make_pair(31,33),
make_pair(26,28) } ;

vector<int> func(vector<int> idx , int x )
{
	vector<int> v = {idx[0], idx[1] } ;
	if( isLarger(idx[0], idx[1], x ) ) swap(v[0], v[1] );	

	for(int i = 2 ; i < sz(idx) ; i++ )
	{
		int l = 0 , r = sz(v)-1 , mid , best = -1 ;
		while( l <= r )
		{
			mid = (l+r)>>1 ;
			if( isLarger(idx[i], v[mid],x  ) )
			{
				best = mid ;
				l = mid+1 ;
			}
			else r = mid-1 ;
		}			

		vector<int> newV ;
		if( best == -1 ) newV.push_back(idx[i]) ;
			
		for(int j = 0 ; j < sz(v) ; j++ )
		{
			newV.push_back(v[j] ) ;
			if( j == best ) newV.push_back( idx[i] ) ;
		}

		swap(newV, v) ;

	}

	return v ;

}


void solve(vector<int> v, int R )
{

	if(sz(v) == 1 ) return (void)( p[ v[0] ] = R ) ;

	int w ;
	if( R <= 2 ) w = 1 ;
	else if(R <= 8 ) w = 2 ; 
	else if( R <= 30 ) w = 4 ;
	else if( R <= 84 ) w = 7 ;
	else w = 8 ;

	if( sz(v) == 2 )
	{
		clean() ;
		b[ v[0] ] = b[ v[1] ] = w ;
		p[ v[1] ] = R , p[ v[0] ] = R-1 ;

		playRound(b,r);

		if( b[ v[0] ] < r[ v[0] ] ) swap(p[v[1]], p[v[0]] ) ;

		return ;

	}

	int cost = R/sz(v) ;
	int L = R - sz(v) + 1 ;

	for(auto e : forbidden )
		if( make_pair(L,R) == e ) 
		{
			v=func(v,w) ;
			for(int i = sz(v)-1 ; i >= 0 ; i-- ) p[ v[i] ] = R-- ;
			return ;
		}

	clean() ;

	for(int i : v ) b[i] = cost ;

	playRound(b,r) ;

	vector<int> lef, rig ;

	for(int i : v ) 
	{
		if( b[i] < r[i] ) rig.push_back(i) ; 
		else lef.push_back(i) ;
	}

	if(sz(rig) ) solve(rig, R) ;
	if(sz(lef) ) solve(lef, R-sz(rig) ) ;

}

void allValues(int N, int W, int *P) 
{

    if (W == 2*N) 
    {
		vector<int> idx(N) ; iota(all(idx),0) ;
		vector<int> v = func(idx, 100 ) ;
 
		for(int i = 0 ; i < N ; i++ ) P[ v[i] ] = i+1 ;
    } 
    else 
    {
    	
		for(int i = 0 ; i < N ; i++ ) p[i] = 0 ;

		vector<int> v(N) ; iota(all(v), 0) ;
		solve(v,100) ;

		for(int i = 0 ; i < N ; i++ ) P[i] = p[i] ;

    }       	
}

Compilation message

koala.cpp: In function 'int minValue(int, int)':
koala.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
   25 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 364 KB Output is correct
2 Correct 6 ms 364 KB Output is correct
3 Correct 6 ms 364 KB Output is correct
4 Correct 8 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 364 KB Output is correct
2 Correct 18 ms 384 KB Output is correct
3 Correct 18 ms 364 KB Output is correct
4 Correct 19 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 492 KB Output is correct
2 Correct 87 ms 364 KB Output is correct
3 Correct 73 ms 364 KB Output is correct
4 Correct 71 ms 364 KB Output is correct
5 Correct 73 ms 384 KB Output is correct
6 Correct 85 ms 492 KB Output is correct
7 Correct 73 ms 364 KB Output is correct
8 Correct 76 ms 364 KB Output is correct
9 Correct 74 ms 364 KB Output is correct
10 Correct 72 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 364 KB Output is correct
2 Correct 44 ms 492 KB Output is correct
3 Correct 43 ms 364 KB Output is correct
4 Correct 44 ms 364 KB Output is correct
5 Correct 49 ms 512 KB Output is correct
6 Correct 43 ms 364 KB Output is correct
7 Correct 44 ms 364 KB Output is correct
8 Correct 48 ms 364 KB Output is correct
9 Correct 43 ms 364 KB Output is correct
10 Correct 44 ms 492 KB Output is correct
11 Correct 43 ms 364 KB Output is correct
12 Correct 38 ms 364 KB Output is correct
13 Correct 43 ms 364 KB Output is correct
14 Correct 47 ms 364 KB Output is correct
15 Correct 43 ms 364 KB Output is correct
16 Correct 42 ms 364 KB Output is correct
17 Correct 43 ms 364 KB Output is correct
18 Correct 45 ms 364 KB Output is correct
19 Correct 43 ms 520 KB Output is correct
20 Correct 48 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 6 ms 364 KB Output is partially correct
2 Partially correct 5 ms 364 KB Output is partially correct
3 Partially correct 5 ms 364 KB Output is partially correct
4 Partially correct 5 ms 364 KB Output is partially correct
5 Partially correct 6 ms 492 KB Output is partially correct
6 Partially correct 5 ms 384 KB Output is partially correct
7 Partially correct 5 ms 364 KB Output is partially correct
8 Partially correct 5 ms 364 KB Output is partially correct
9 Partially correct 5 ms 364 KB Output is partially correct
10 Partially correct 5 ms 396 KB Output is partially correct
11 Partially correct 5 ms 364 KB Output is partially correct
12 Partially correct 6 ms 364 KB Output is partially correct
13 Partially correct 6 ms 364 KB Output is partially correct
14 Partially correct 5 ms 364 KB Output is partially correct
15 Partially correct 5 ms 364 KB Output is partially correct
16 Partially correct 5 ms 384 KB Output is partially correct
17 Partially correct 5 ms 364 KB Output is partially correct
18 Partially correct 5 ms 364 KB Output is partially correct
19 Partially correct 5 ms 364 KB Output is partially correct
20 Partially correct 6 ms 364 KB Output is partially correct
21 Partially correct 5 ms 364 KB Output is partially correct
22 Partially correct 5 ms 384 KB Output is partially correct
23 Partially correct 6 ms 364 KB Output is partially correct
24 Partially correct 5 ms 364 KB Output is partially correct
25 Partially correct 5 ms 364 KB Output is partially correct
26 Partially correct 5 ms 364 KB Output is partially correct
27 Partially correct 5 ms 364 KB Output is partially correct
28 Partially correct 6 ms 364 KB Output is partially correct
29 Partially correct 5 ms 364 KB Output is partially correct
30 Partially correct 5 ms 364 KB Output is partially correct
31 Partially correct 5 ms 364 KB Output is partially correct
32 Partially correct 5 ms 364 KB Output is partially correct
33 Partially correct 7 ms 364 KB Output is partially correct
34 Partially correct 5 ms 364 KB Output is partially correct
35 Partially correct 5 ms 364 KB Output is partially correct
36 Partially correct 5 ms 364 KB Output is partially correct
37 Partially correct 5 ms 364 KB Output is partially correct
38 Partially correct 6 ms 364 KB Output is partially correct
39 Partially correct 6 ms 364 KB Output is partially correct
40 Partially correct 5 ms 364 KB Output is partially correct