Artifact Content
Not logged in

Artifact 581a4d8a9088ed2398a1adc4d41b3ab441ed36fc


#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 VolleyballTournament
{
public:
	string reconstructResults(int wonMatches, int lostMatches, int wonSets, int lostSets) 
	{
		//0-3, 1-3, 2-3, 3-0, 3-1, 3-2
		//Z0   Z1   Z2   W0   W1   W2

		//Z0+    Z1   + Z2                  == lostMatches
		//Z0*0 + Z1*1 + Z2*2 + 3*wonMatches == wonSets

		//W0+W1+W2 == wonMatches
		//W0*0+W1*1+W2*2+3*lostMatches == lostSets

		int a[6] = {-1};
		for(int Z1=0; Z1<=lostMatches; ++Z1)
		{
			int Z2 = (wonSets - 3*wonMatches - Z1) / 2;
			int Z0 = lostMatches - Z1 - Z2;
			if( Z0<0 || Z2<0 || lostMatches<Z0 || lostMatches<Z2 ) continue;
			if( Z1+Z2*2+3*wonMatches != wonSets ) continue;

			for(int W1=0; W1<=wonMatches; ++W1)
			{
				int W2 = (lostSets - 3*lostMatches - W1) / 2;
				int W0 = wonMatches - W1 - W2;
				if( W0<0 || W2<0 || wonMatches<W0 || wonMatches<W2 ) continue;
				if( W1+W2*2+3*lostMatches != lostSets ) continue;

				if( a[0]>=0 )
					return "AMBIGUITY";
				else
					a[0]=Z0, a[1]=Z1, a[2]=Z2, a[3]=W0, a[4]=W1, a[5]=W2;
			}
		}
		const char* s[6] = {"0-3", "1-3", "2-3", "3-0", "3-1", "3-2"};

		string ans;
		for(int i=0; i<6; ++i)
			for(int j=0; j<a[i]; ++j)
				ans += s[i], ans += ",";
		ans.resize(ans.size()-1);
		return ans;
	}

// 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(); }
	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 string &Expected, const string &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 = 3; int Arg1 = 3; int Arg2 = 9; int Arg3 = 9; string Arg4 = "0-3,0-3,0-3,3-0,3-0,3-0"; verify_case(0, Arg4, reconstructResults(Arg0, Arg1, Arg2, Arg3)); }
	void test_case_1() { int Arg0 = 0; int Arg1 = 3; int Arg2 = 6; int Arg3 = 9; string Arg4 = "2-3,2-3,2-3"; verify_case(1, Arg4, reconstructResults(Arg0, Arg1, Arg2, Arg3)); }
	void test_case_2() { int Arg0 = 3; int Arg1 = 0; int Arg2 = 9; int Arg3 = 3; string Arg4 = "AMBIGUITY"; verify_case(2, Arg4, reconstructResults(Arg0, Arg1, Arg2, Arg3)); }
	void test_case_3() { int Arg0 = 1; int Arg1 = 1; int Arg2 = 4; int Arg3 = 4; string Arg4 = "1-3,3-1"; verify_case(3, Arg4, reconstructResults(Arg0, Arg1, Arg2, Arg3)); }

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