Skip to content

Instantly share code, notes, and snippets.

@iseki-masaya
Created April 23, 2015 02:19
Show Gist options
  • Save iseki-masaya/96ae0cfff4d84fa92974 to your computer and use it in GitHub Desktop.
Save iseki-masaya/96ae0cfff4d84fa92974 to your computer and use it in GitHub Desktop.
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <algorithm>
#include <sstream>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cstdlib>
#include <cstring>
#include <numeric>
#include <bitset>
#include <deque>
#include <memory>
const long long LINF = (5e17);
const int INF = 1000000000;
#define EPS 1e-7
const int MOD = 1000000007;
using namespace std;
class BichromePainting {
public:
bool isIn(int x, int y, int X, int Y) {
return 0 <= x && x < X && 0 <= y && y < Y;
}
string isThatPossible(vector <string> board, int k) {
int Y = (int)board.size();
int X = (int)board[0].size();
bool update = true;
while (update) {
update = false;
for (int y=0; y<Y; ++y) {
for (int x=0; x<X; ++x) {
if (!isIn(x + k - 1, y + k - 1, X, Y))
continue;
char prev = '?';
bool enable = true;
for (int dx=0; dx<k; ++dx) {
for (int dy=0; dy<k; ++dy) {
if (prev != '?' && board[y+dy][x+dx] != '?' && prev != board[y+dy][x+dx])
enable = false;
if (prev == '?')
prev = board[y+dy][x+dx];
}
}
if (enable) {
char isAllQuestion = true;
for (int dx=0; dx<k; ++dx) {
for (int dy=0; dy<k; ++dy) {
if (board[y+dy][x+dx] != '?')
isAllQuestion = false;
board[y+dy][x+dx] = '?';
}
}
if (!isAllQuestion)
update = true;
}
}
}
}
for (int y=0; y<Y; ++y)
for (int x=0; x<X; ++x)
if (board[y][x] != '?')
return "Impossible";
return "Possible";
}
// BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); if ((Case == -1) || (Case == 6)) test_case_6(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { string Arr0[] = {"BBBW",
"BWWW",
"BWWW",
"WWWW"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; string Arg2 = "Possible"; verify_case(0, Arg2, isThatPossible(Arg0, Arg1)); }
void test_case_1() { string Arr0[] = {"BW",
"WB"}
; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 2; string Arg2 = "Impossible"; verify_case(1, Arg2, isThatPossible(Arg0, Arg1)); }
void test_case_2() { string Arr0[] = {"BWBWBB",
"WBWBBB",
"BWBWBB",
"WBWBBB",
"BBBBBB",
"BBBBBB"}
; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 2; string Arg2 = "Possible"; verify_case(2, Arg2, isThatPossible(Arg0, Arg1)); }
void test_case_3() { string Arr0[] = {"BWBWBB",
"WBWBWB",
"BWBWBB",
"WBWBWB",
"BWBWBB",
"BBBBBB"}
; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 2; string Arg2 = "Impossible"; verify_case(3, Arg2, isThatPossible(Arg0, Arg1)); }
void test_case_4() { string Arr0[] = {"BWBWBB",
"WBWBWB",
"BWBWBB",
"WBWBWB",
"BWBWBB",
"BBBBBB"}
; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 1; string Arg2 = "Possible"; verify_case(4, Arg2, isThatPossible(Arg0, Arg1)); }
void test_case_5() { string Arr0[] = {"BB",
"BB"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 2; string Arg2 = "Possible"; verify_case(5, Arg2, isThatPossible(Arg0, Arg1)); }
void test_case_6() { string Arr0[] = {"WBWBBBWBBWWBBBBWB", "BWWWBBWBWBWWBWBWB", "BBBBBBWBWBBWBBBBW", "WBBWBWBWWWBBBWBBB", "BWWBBBBBWBBWBBWWB", "BBBWBBBBBWBBWBBWW", "BWBWBBWBWBWBWBBWB", "BBWBWBWBBWBBWWBWW", "BBBWWWWWBWBWWBWBB", "WBBBWBBBBWBBWBWBB", "WBBWBBBWBBBWBWWWB", "BWBBBBWBBBWBBWWWW", "WWBWWWWWBBWWWBBBW", "BWWBWBBWBWBBWWWBB", "BBWWBBBWWWWBWBWWW", "BWBBBBBBWWWBWBWWB", "BBWWWBWBBBWWWWBWB"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 2; string Arg2 = "Possible"; verify_case(6, Arg2, isThatPossible(Arg0, Arg1)); }
// END CUT HERE
};
// BEGIN CUT HERE
int main() {
BichromePainting ___test;
___test.run_test(-1);
}
// END CUT HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment