Artifact Content
Not logged in

Artifact 2e6ce5bbe0d9efd7fee99644339db9c20bfb1c12


#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>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class NetworkXZeroOne { public:
	string reconstruct(string message)
	{
		if( message[0]=='?' ) {
			string msg = message;
			msg[0] = 'o';
			if( check(msg) )
				return msg;
			message[0] = 'x';
		}
		check(message);
		return message;
	}

	bool check(string& msg)
	{
		for(int i=1; i<msg.size(); ++i)
			if( msg[i]=='?' ) {
				if( msg[i-1]=='x' )
					msg[i]='o';
				else
					msg[i]='x';
			}
		for(int i=0; i<msg.size(); ++i)
			for(int k=2; i+k<=msg.size(); k+=2)
				if( count(msg.begin()+i, msg.begin()+i+k, 'o')*2 != k )
					return false;
		return true;
	}
};

// 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(_, NetworkXZeroOne().reconstruct(message));}
int main(){

CASE(0)
	string message = "x?x?"; 
	string _ = "xoxo"; 
END
CASE(1)
	string message = "?xo?"; 
	string _ = "oxox"; 
END
CASE(2)
	string message = "xo"; 
	string _ = "xo"; 
END
CASE(3)
	string message = "o??x??o"; 
	string _ = "oxoxoxo"; 
END
CASE(4)
	string message = "???????x"; 
	string _ = "oxoxoxox"; 
END
/*
CASE(5)
	string message = ; 
	string _ = ; 
END
CASE(6)
	string message = ; 
	string _ = ; 
END
*/
}
// END CUT HERE