Artifact Content
Not logged in

Artifact db13cb4122e4e0d1a4b96ccdbecf829d112f8a4a


#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 TaroJiroGrid { public:
	int getNumber(vector <string> grid)
	{
		const int H = grid.size();
		const int W = grid[0].size();
		const string Change[2] = {string(W, 'B'), string(W, 'W')};

		// 0
		if(ok(grid))
			return 0;
		// 1
		for(int y1=0; y1<H; ++y1) for(int c1=0; c1<2; ++c1) {
			auto t1 = grid[y1];
			grid[y1] = Change[c1];
			if(ok(grid)) return 1;
			grid[y1] = t1;
		}
		return 2;
	}

	bool ok(const vector<string>& g)
	{
		const int H = g.size();
		const int W = g[0].size();
		for(int x=0; x<W; ++x) {
			int nb=0, nw=0;
			for(int y=0; y<H; ++y)
			{
				if(g[y][x]=='B') nb++, nw=0;
				else nb=0, nw++;
				if(nw>H/2 || nb>H/2)
					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 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(_, TaroJiroGrid().getNumber(grid));}
int main(){

CASE(0)
	string grid_[] = {"WB",
 "BB"};
	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
	int _ = 1; 
END
CASE(1)
	string grid_[] = {"WB",
 "WW"};
	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
	int _ = 1; 
END
CASE(2)
	string grid_[] = {"WB",
 "WB"};
	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
	int _ = 2; 
END
CASE(3)
	string grid_[] = {"WBBW",
 "WBWB",
 "WWBB",
 "BWWW"};
	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
	int _ = 2; 
END
CASE(4)
	string grid_[] = {"WBBWBB",
 "BBWBBW",
 "WWBWBW",
 "BWWBBB",
 "WBWBBW",
 "WWWBWB"};
	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
	int _ = 1; 
END
/*
CASE(5)
	string grid_[] = ;
	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
	int _ = ; 
END
CASE(6)
	string grid_[] = ;
	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
	int _ = ; 
END
*/
}
// END CUT HERE