Artifact 1d275d88bba6cbca848821b1853cd04fb4f9bff9
#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class SwitchingGame { public:
int timeToWin(vector <string> states)
{
const int W = states[0].size();
string cur(W, '-');
int sec = 0;
for(int i=0; i<states.size(); ++i)
{
bool need_flip_to_minus = false;
bool need_flip_to_plus = false;
for(int k=0; k<W; ++k) {
if(states[i][k]=='-' && cur[k]=='+')
need_flip_to_minus = true;
if(states[i][k]=='+' && cur[k]=='-')
need_flip_to_plus = true;
}
for(int k=0; k<W; ++k) {
switch(states[i][k])
{
case '-':
cur[k] = '-';
break;
case '+':
cur[k] = '+';
break;
case '?':
for(int j=i+1; j<states.size(); ++j) {
if(states[j][k]=='-') {if(need_flip_to_minus)cur[k]='-';break;}
if(states[j][k]=='+') {if(need_flip_to_plus)cur[k]='+';break;}
}
break;
}
}
sec += 1 + need_flip_to_plus + need_flip_to_minus;
}
return sec;
}
};
// 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 int& Expected, const int& 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(_, SwitchingGame().timeToWin(states));}
int main(){
CASE(1)
string states_[] = {"+-++",
"+-++"};
vector <string> states(states_, states_+sizeof(states_)/sizeof(*states_));
int _ = 3;
END
CASE(0)
string states_[] = {"++--",
"--++"};
vector <string> states(states_, states_+sizeof(states_)/sizeof(*states_));
int _ = 5;
END
CASE(2)
string states_[] = {"++",
"+?",
"?+",
"++"};
vector <string> states(states_, states_+sizeof(states_)/sizeof(*states_));
int _ = 5;
END
CASE(3)
string states_[] = {"+",
"?",
"?",
"?",
"-"};
vector <string> states(states_, states_+sizeof(states_)/sizeof(*states_));
int _ = 7;
END
CASE(4)
string states_[] = {"+??+++",
"++??+-",
"?++??+",
"?-+-??",
"??+?++",
"++-?+?",
"?++?-+",
"?--+++",
"-??-?+"}
;
vector <string> states(states_, states_+sizeof(states_)/sizeof(*states_));
int _ = 20;
END
/*
CASE(5)
string states_[] = ;
vector <string> states(states_, states_+sizeof(states_)/sizeof(*states_));
int _ = ;
END
CASE(6)
string states_[] = ;
vector <string> states(states_, states_+sizeof(states_)/sizeof(*states_));
int _ = ;
END
*/
}
// END CUT HERE