Artifact Content
Not logged in

Artifact 51d9cbf8cbd5563061ea2a1e135216e1089472f0


#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 SquareCutout { public:
	int verify(vector <string> cutout)
	{
		const int Y = cutout.size(), X = cutout[0].size();

		bool has_black = false;
		for (int y = 0; y < Y; ++y)
			for (int x = 0; x < X; ++x)
				if (cutout[y][x] == '#')
					has_black = true;
		if (!has_black)
			return 1;

		int ym = Y, xm = X, yM = 0, xM = 0;
		for (int y = 0; y < Y; ++y)
			for (int x = 0; x < X; ++x)
				if (cutout[y][x] == '#')
					ym = min(ym, y), yM = max(yM, y), xm = min(xm, x), xM = max(xM, x);

		for (int y = ym; y <= yM; ++y)
			for (int x = xm; x <= xM; ++x)
				if (cutout[y][x] != '#')
					return 0;

		bool x_extendable = (xm == 0 || xM == X - 1);
		bool y_extendable = (ym == 0 || yM == Y - 1);
		int yy = yM - ym + 1;
		int xx = xM - xm + 1;
		if (yy == xx)
			return yy;
		if (yy < xx)
			return y_extendable ? xx : 0;
		return x_extendable ? yy : 0;
	}
};

// 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(_, SquareCutout().verify(cutout));}
int main(){

CASE(0)
	string cutout_[] = {".....",
 "..##.",
 "..##.",
 ".....",
 "....."};
	  vector <string> cutout(cutout_, cutout_+sizeof(cutout_)/sizeof(*cutout_)); 
	int _ = 2; 
END
CASE(1)
	string cutout_[] = {"...",
 "..."};
	  vector <string> cutout(cutout_, cutout_+sizeof(cutout_)/sizeof(*cutout_)); 
	int _ = 1; 
END
CASE(2)
	string cutout_[] = {".....",
 ".###.",
 ".#.#.",
 ".###.",
 "....."};
	  vector <string> cutout(cutout_, cutout_+sizeof(cutout_)/sizeof(*cutout_)); 
	int _ = 0; 
END
CASE(3)
	string cutout_[] = {"..####",
 "..####",
 "......"};
	  vector <string> cutout(cutout_, cutout_+sizeof(cutout_)/sizeof(*cutout_)); 
	int _ = 4; 
END
CASE(4)
	string cutout_[] = {"..#..",
 ".###.",
 "#####",
 ".###.",
 "..#.."};
	  vector <string> cutout(cutout_, cutout_+sizeof(cutout_)/sizeof(*cutout_)); 
	int _ = 0; 
END
CASE(5)
string cutout_[] = { "...", "...", "..." };
	  vector <string> cutout(cutout_, cutout_+sizeof(cutout_)/sizeof(*cutout_)); 
	int _ = 1; 
END
/*
CASE(6)
	string cutout_[] = ;
	  vector <string> cutout(cutout_, cutout_+sizeof(cutout_)/sizeof(*cutout_)); 
	int _ = ; 
END
*/
}
// END CUT HERE