Artifact f84d4323f44297d3a037a2951bf52aab03f05e00
#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 BichromePainting { public:
string isThatPossible(vector <string> board, int k)
{
return solve(board, k) ? "Possible" : "Impossible";
}
bool solve(vector<string> board, int K)
{
while(!no_black(board))
if(!step_back(board, K))
return false;
return true;
}
bool no_black(const vector<string>& board)
{
const int H = board.size();
const int W = board[0].size();
for(int y=0; y<H; ++y)
for(int x=0; x<W; ++x) if(board[y][x] == 'B')
return false;
return true;
}
bool step_back(vector<string>& board, int K) {
bool updated = false;
const int H = board.size();
const int W = board[0].size();
for(int y=0; y+K<=H; ++y)
for(int x=0; x+K<=W; ++x) {
bool has_white = false;
bool has_black = false;
for(int dy=0; dy<K; ++dy)
for(int dx=0; dx<K; ++dx) {
if(board[y+dy][x+dx]=='W') has_white=true;
if(board[y+dy][x+dx]=='B') has_black=true;
}
if(has_white && has_black)
continue;
if(has_white || has_black) {
for(int dy=0; dy<K; ++dy)
for(int dx=0; dx<K; ++dx)
board[y+dy][x+dx] = '*';
updated = true;
}
}
return updated;
}
};
// 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(_, BichromePainting().isThatPossible(board, k));}
int main(){
CASE(0)
string board_[] = {"BBBW",
"BWWW",
"BWWW",
"WWWW"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
int k = 3;
string _ = "Possible";
END
CASE(1)
string board_[] = {"BW",
"WB"}
;
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
int k = 2;
string _ = "Impossible";
END
CASE(2)
string board_[] = {"BWBWBB",
"WBWBBB",
"BWBWBB",
"WBWBBB",
"BBBBBB",
"BBBBBB"}
;
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
int k = 2;
string _ = "Possible";
END
CASE(3)
string board_[] = {"BWBWBB",
"WBWBWB",
"BWBWBB",
"WBWBWB",
"BWBWBB",
"BBBBBB"}
;
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
int k = 2;
string _ = "Impossible";
END
CASE(4)
string board_[] = {"BWBWBB",
"WBWBWB",
"BWBWBB",
"WBWBWB",
"BWBWBB",
"BBBBBB"}
;
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
int k = 1;
string _ = "Possible";
END
CASE(5)
string board_[] = {"BB",
"BB"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
int k = 2;
string _ = "Possible";
END
CASE(6)
string board_[] = {"BBWW", "BBWW", "WBBW", "WWWW"};
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
int k = 2;
string _ = "Possible";
END
/*
CASE(7)
string board_[] = ;
vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_));
int k = ;
string _ = ;
END
*/
}
// END CUT HERE