Artifact 0a31ef5a52a2efc2bd2cfdec13315426623695cb
#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 ConnectingGame { public:
string isValid(vector <string> board)
{
return hasCuttingPaint(board) ? "invalid" : "valid";
}
bool hasCuttingPaint(vector<string> board) {
const int H = board.size();
const int W = board[0].size();
if(H==1 || W==1)
return false;
set<char> T,L,R,B;
map<char, set<char>> G;
for(int y=0; y<H; ++y)
for(int x=0; x<W; ++x)
{
if(y==0) T.insert(board[y][x]);
if(y==H-1) B.insert(board[y][x]);
if(x==0) L.insert(board[y][x]);
if(x==W-1) R.insert(board[y][x]);
int dy[]={0,0,-1,+1};
int dx[]={-1,+1,0,0};
for(int d=0; d<4; ++d) {
int yy=y+dy[d], xx=x+dx[d];
if(0<=yy&&yy<H&&0<=xx&&xx<W&&board[y][x]!=board[yy][xx])
G[board[y][x]].insert(board[yy][xx]);
}
}
// Is there a way to paint nodes in G s.t.
// - all L~G~R paths have at least one Blue node, and
// - all T~G~B paths have at least one Red node?
// |G|<=62.
}
};
// 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(_, ConnectingGame().isValid(board));}
int main(){
CASE(0)
string board_[] = {"AAB"
,"CCD"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
string _ = "invalid";
END
CASE(1)
string board_[] = {"AA"
,"BB"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
string _ = "valid";
END
CASE(2)
string board_[] = {"iii"
,"iwi"
,"iii"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
string _ = "valid";
END
CASE(3)
string board_[] = {"SSnukee"
,"SKnuthe"
,"SSSothe"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
string _ = "invalid";
END
CASE(4)
string board_[] = {"rng58"
,"rnggn"
,"rnnnn"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
string _ = "valid";
END
CASE(5)
string board_[] = {"ggssGGGGGG","ggssspGGGG","ggsssppGGG","ggWsspGGGG","gggsspGGiG","g7ssspGGGG","gggsseKK33","gggssssK33","gHgsssHA33","HHHHHHHHHH","HHHHHHHHH6","HHHHHHHHb6"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
string _ = "invalid";
END
/*
CASE(6)
string board_[] = ;
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
string _ = ;
END
CASE(7)
string board_[] = ;
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
string _ = ;
END
*/
}
// END CUT HERE