Artifact Content
Not logged in

Artifact ff253b1becebd34826a884e59dbb04650358ceff


#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>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class EllysCheckers { public:
	string getWinner(string board)
	{
		int N = board.size()-1;
		int mask = 0;
		for(int i=0; i<N; ++i)
			mask |= (board[i]=='o')<<i;
		vector<int> memo(1<<N, -1);
		return win(memo, N, mask) ? "YES" : "NO";
	}

	bool win(vector<int>& memo, int N, int mask)
	{
		mask &= (1<<N)-1;
		if( memo[mask] != -1 )
			return memo[mask];
		if( mask == 0 ) // no checker, no move => lose
			return 0;

		bool I_win = false;
		// enumerate all possible moves
		for(int i=0; i<N; ++i)
			if( mask & (1<<i) ) {
				if( !(mask & (1<<i+1)) ) { // step
					int newmask = mask &~ (1<<i) | (1<<i+1);
					if( !win(memo, N, newmask) )
						I_win = true;
				}
				if( (mask & (1<<i+1)) && (mask & (1<<i+2)) && !(mask & (1<<i+3)) ) { // jump
					int newmask = mask &~ (1<<i) | (1<<i+3);
					if( !win(memo, N, newmask) )
						I_win = true;
				}
			}
		return memo[mask] = I_win;
	}
};

// 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(_, EllysCheckers().getWinner(board));}
int main(){

CASE(0)
	string board = ".o..."; 
	string _ = "YES"; 
END
CASE(1)
	string board = "..o..o"; 
	string _ = "YES"; 
END
CASE(2)
	string board = ".o...ooo..oo.."; 
	string _ = "NO"; 
END
CASE(3)
	string board = "......o.ooo.o......"; 
	string _ = "YES"; 
END
CASE(4)
	string board = ".o..o...o....o.....o"; 
	string _ = "NO"; 
END
CASE(5)
	string board = "oooooooooooooooooooo"; 
	string _ = "?"; 
END
CASE(6)
	string board = "o.o.o.o.o.o.o.o.o.o."; 
	string _ = "?"; 
END
CASE(7)
	string board = "."; 
	string _ = "NO"; 
END
CASE(8)
	string board = "."; 
	string _ = "NO"; 
END
CASE(9)
	string board = "o."; 
	string _ = "YES"; 
END

}
// END CUT HERE