Artifact 03cf07f878cb30743934c711bd8ead0345aa17e5
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;
class TheNumberGame { public:
string determineOutcome(int A, int B)
{
string S; {stringstream sin; sin<<A; sin>>S;}
string T; {stringstream sin; sin<<B; sin>>T;}
return rec(S,T) ? "Manao wins" : "Manao loses";
}
map<pair<string,string>, bool> memo;
bool rec(const string& S, const string& T)
{
if(S == T)
return false;
pair<string, string> key(S, T);
if(memo.count(key))
return memo[key];
bool aWin = false;
for(int a=0; a<2; ++a)
{
string S1 = op(S, a);
aWin |= (S1 == T);
bool bWin = false;
for(int b=0; b<2; ++b)
{
string T1 = op(T, b);
bWin |= (S1 == T1);
bool cWin = false;
for(int c=0; c<2; ++c)
{
string S2 = op(S1, c);
cWin |= (S2 == T1);
bool dWin = false;
for(int d=0; d<2; ++d)
{
string T2 = op(T1, d);
dWin |= (S2 == T2);
if(S==S2 || T==T2)
dWin |= true;
else
dWin |= !rec(S2, T2);
}
cWin |= !dWin;
}
bWin |= !cWin;
}
aWin |= !bWin;
}
return memo[key] = aWin;
}
string op(const string& s, int i)
{
if(i==0)
return s.empty() ? s : s.substr(0, s.size()-1);
else
return string(s.rbegin(), s.rend());
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, TheNumberGame().determineOutcome(A, B));}
int main(){
CASE(0)
int A = 45;
int B = 4;
string _ = "Manao wins";
END
CASE(1)
int A = 45;
int B = 5;
string _ = "Manao wins";
END
CASE(2)
int A = 99;
int B = 123;
string _ = "Manao loses";
END
CASE(3)
int A = 2356236;
int B = 5666;
string _ = "Manao loses";
END
/*
CASE(4)
int A = ;
int B = ;
string _ = ;
END
CASE(5)
int A = ;
int B = ;
string _ = ;
END
*/
}
// END CUT HERE