Artifact Content
Not logged in

Artifact 3ecdbbbf9c0cd8ea8daabf9121078ef0f841a953


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long LL;

class RPSTournament
{
public:
	int greatestSeed(int rounds, int C) 
	{
		int L=1, R=(1<<rounds)+1;
		while( R-L > 1) {
			int M = (L+R)/2;
			(can_win(M, rounds, C) ? L : R) = M;
		}
		return L;
	}

	bool can_win(int X, int R, int C)
	{
		queue< pair<int,int> > Q;
		Q.push( make_pair(R, X) );

		set<int> unused;
		for(int n=0; n<=(1<<R); ++n)
			if( n!=X )
				unused.insert(n);

		while( !Q.empty() ) {
			int r=Q.front().first;
			int x=Q.front().second;
			Q.pop();

			int xl = x-(int)sqrt((double)C*x);
			set<int>::iterator it = unused.lower_bound(xl);
			if( it==unused.end() )
				return false;
			if(r > 1) {
				Q.push( make_pair(r-1,max(*it,x)) );
				Q.push( make_pair(r-1,min(*it,x)) );
			}
			unused.erase(it);
		}
		return true;
	}

// BEGIN CUT HERE
	public:
	void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
	private:
	template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
	void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
	void test_case_0() { int Arg0 = 2; int Arg1 = 0; int Arg2 = 1; verify_case(0, Arg2, greatestSeed(Arg0, Arg1)); }
	void test_case_1() { int Arg0 = 3; int Arg1 = 1; int Arg2 = 6; verify_case(1, Arg2, greatestSeed(Arg0, Arg1)); }
	void test_case_2() { int Arg0 = 4; int Arg1 = 1; int Arg2 = 9; verify_case(2, Arg2, greatestSeed(Arg0, Arg1)); }
	void test_case_3() { int Arg0 = 7; int Arg1 = 3; int Arg2 = 50; verify_case(3, Arg2, greatestSeed(Arg0, Arg1)); }
	void test_case_4() { int Arg0 = 15; int Arg1 = 180; int Arg2 = 9755; verify_case(4, Arg2, greatestSeed(Arg0, Arg1)); }

// END CUT HERE
};
// BEGIN CUT HERE 
int main() { RPSTournament().run_test(-1); }
// END CUT HERE