148e3f363b 2011-09-10 kinaba: #include <iostream> 148e3f363b 2011-09-10 kinaba: #include <sstream> 148e3f363b 2011-09-10 kinaba: #include <iomanip> 148e3f363b 2011-09-10 kinaba: #include <vector> 148e3f363b 2011-09-10 kinaba: #include <string> 148e3f363b 2011-09-10 kinaba: #include <map> 148e3f363b 2011-09-10 kinaba: #include <set> 148e3f363b 2011-09-10 kinaba: #include <algorithm> 148e3f363b 2011-09-10 kinaba: #include <numeric> 148e3f363b 2011-09-10 kinaba: #include <iterator> 148e3f363b 2011-09-10 kinaba: #include <functional> 148e3f363b 2011-09-10 kinaba: #include <complex> 148e3f363b 2011-09-10 kinaba: #include <queue> 148e3f363b 2011-09-10 kinaba: #include <stack> 148e3f363b 2011-09-10 kinaba: #include <cmath> 148e3f363b 2011-09-10 kinaba: #include <cassert> 148e3f363b 2011-09-10 kinaba: #include <cstring> 148e3f363b 2011-09-10 kinaba: using namespace std; 148e3f363b 2011-09-10 kinaba: typedef long long LL; 148e3f363b 2011-09-10 kinaba: typedef complex<double> CMP; 148e3f363b 2011-09-10 kinaba: 148e3f363b 2011-09-10 kinaba: class NetworkXZeroOne { public: 148e3f363b 2011-09-10 kinaba: string reconstruct(string message) 148e3f363b 2011-09-10 kinaba: { 148e3f363b 2011-09-10 kinaba: if( message[0]=='?' ) { 148e3f363b 2011-09-10 kinaba: string msg = message; 148e3f363b 2011-09-10 kinaba: msg[0] = 'o'; 148e3f363b 2011-09-10 kinaba: if( check(msg) ) 148e3f363b 2011-09-10 kinaba: return msg; 148e3f363b 2011-09-10 kinaba: message[0] = 'x'; 148e3f363b 2011-09-10 kinaba: } 148e3f363b 2011-09-10 kinaba: check(message); 148e3f363b 2011-09-10 kinaba: return message; 148e3f363b 2011-09-10 kinaba: } 148e3f363b 2011-09-10 kinaba: 148e3f363b 2011-09-10 kinaba: bool check(string& msg) 148e3f363b 2011-09-10 kinaba: { 148e3f363b 2011-09-10 kinaba: for(int i=1; i<msg.size(); ++i) 148e3f363b 2011-09-10 kinaba: if( msg[i]=='?' ) { 148e3f363b 2011-09-10 kinaba: if( msg[i-1]=='x' ) 148e3f363b 2011-09-10 kinaba: msg[i]='o'; 148e3f363b 2011-09-10 kinaba: else 148e3f363b 2011-09-10 kinaba: msg[i]='x'; 148e3f363b 2011-09-10 kinaba: } 148e3f363b 2011-09-10 kinaba: for(int i=0; i<msg.size(); ++i) 148e3f363b 2011-09-10 kinaba: for(int k=2; i+k<=msg.size(); k+=2) 148e3f363b 2011-09-10 kinaba: if( count(msg.begin()+i, msg.begin()+i+k, 'o')*2 != k ) 148e3f363b 2011-09-10 kinaba: return false; 148e3f363b 2011-09-10 kinaba: return true; 148e3f363b 2011-09-10 kinaba: } 148e3f363b 2011-09-10 kinaba: }; 148e3f363b 2011-09-10 kinaba: 148e3f363b 2011-09-10 kinaba: // BEGIN CUT HERE 148e3f363b 2011-09-10 kinaba: #include <ctime> 148e3f363b 2011-09-10 kinaba: double start_time; string timer() 148e3f363b 2011-09-10 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 148e3f363b 2011-09-10 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 148e3f363b 2011-09-10 kinaba: { os << "{ "; 148e3f363b 2011-09-10 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 148e3f363b 2011-09-10 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 148e3f363b 2011-09-10 kinaba: void verify_case(const string& Expected, const string& Received) { 148e3f363b 2011-09-10 kinaba: bool ok = (Expected == Received); 148e3f363b 2011-09-10 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 148e3f363b 2011-09-10 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 148e3f363b 2011-09-10 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 148e3f363b 2011-09-10 kinaba: #define END verify_case(_, NetworkXZeroOne().reconstruct(message));} 148e3f363b 2011-09-10 kinaba: int main(){ 148e3f363b 2011-09-10 kinaba: 148e3f363b 2011-09-10 kinaba: CASE(0) 148e3f363b 2011-09-10 kinaba: string message = "x?x?"; 148e3f363b 2011-09-10 kinaba: string _ = "xoxo"; 148e3f363b 2011-09-10 kinaba: END 148e3f363b 2011-09-10 kinaba: CASE(1) 148e3f363b 2011-09-10 kinaba: string message = "?xo?"; 148e3f363b 2011-09-10 kinaba: string _ = "oxox"; 148e3f363b 2011-09-10 kinaba: END 148e3f363b 2011-09-10 kinaba: CASE(2) 148e3f363b 2011-09-10 kinaba: string message = "xo"; 148e3f363b 2011-09-10 kinaba: string _ = "xo"; 148e3f363b 2011-09-10 kinaba: END 148e3f363b 2011-09-10 kinaba: CASE(3) 148e3f363b 2011-09-10 kinaba: string message = "o??x??o"; 148e3f363b 2011-09-10 kinaba: string _ = "oxoxoxo"; 148e3f363b 2011-09-10 kinaba: END 148e3f363b 2011-09-10 kinaba: CASE(4) 148e3f363b 2011-09-10 kinaba: string message = "???????x"; 148e3f363b 2011-09-10 kinaba: string _ = "oxoxoxox"; 148e3f363b 2011-09-10 kinaba: END 148e3f363b 2011-09-10 kinaba: /* 148e3f363b 2011-09-10 kinaba: CASE(5) 148e3f363b 2011-09-10 kinaba: string message = ; 148e3f363b 2011-09-10 kinaba: string _ = ; 148e3f363b 2011-09-10 kinaba: END 148e3f363b 2011-09-10 kinaba: CASE(6) 148e3f363b 2011-09-10 kinaba: string message = ; 148e3f363b 2011-09-10 kinaba: string _ = ; 148e3f363b 2011-09-10 kinaba: END 148e3f363b 2011-09-10 kinaba: */ 148e3f363b 2011-09-10 kinaba: } 148e3f363b 2011-09-10 kinaba: // END CUT HERE