Artifact Content
Not logged in

Artifact 8bc8dad70f532eb24755285a261929a4e28f5ea1


#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 ChocolateDividingEasy { public:
	int findBest(vector <string> chocolate)
	{
		const int H = chocolate.size();
		const int W = chocolate[0].size();
		vector<vector<int>> sum(H+1, vector<int>(W+1));
		for(int y=H-1; y>=0; --y)
		for(int x=W-1; x>=0; --x)
			sum[y][x] = (chocolate[y][x]-'0')+sum[y+1][x]+sum[y][x+1]-sum[y+1][x+1];

		int best = 0;
		for(int y1=1; y1<H; ++y1)
		for(int y2=y1+1; y2<H; ++y2)
		for(int x1=1; x1<W; ++x1)
		for(int x2=x1+1; x2<W; ++x2)
		{
			int Y[] = {0, y1, y2, H};
			int X[] = {0, x1, x2, W};
			int smallest = 0x3fffffff;
			for(int i=0; i<3; ++i)
			for(int k=0; k<3; ++k)
			{
				int area = sum[Y[i]][X[k]] - sum[Y[i+1]][X[k]] - sum[Y[i]][X[k+1]] + sum[Y[i+1]][X[k+1]];
				smallest = min(smallest, area);
			}
			best = max(best, smallest);
		}
		return best;
	}
};

// 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(_, ChocolateDividingEasy().findBest(chocolate));}
int main(){

CASE(0)
	string chocolate_[] = {
"9768",
"6767",
"5313"
};
	  vector <string> chocolate(chocolate_, chocolate_+sizeof(chocolate_)/sizeof(*chocolate_)); 
	int _ = 3; 
END
CASE(1)
	string chocolate_[] = {
"36753562",
"91270936",
"06261879",
"20237592",
"28973612",
"93194784"
};
	  vector <string> chocolate(chocolate_, chocolate_+sizeof(chocolate_)/sizeof(*chocolate_)); 
	int _ = 15; 
END
CASE(2)
	string chocolate_[] = {
"012",
"345",
"678"
};
	  vector <string> chocolate(chocolate_, chocolate_+sizeof(chocolate_)/sizeof(*chocolate_)); 
	int _ = 0; 
END
/*
CASE(3)
	string chocolate_[] = ;
	  vector <string> chocolate(chocolate_, chocolate_+sizeof(chocolate_)/sizeof(*chocolate_)); 
	int _ = ; 
END
CASE(4)
	string chocolate_[] = ;
	  vector <string> chocolate(chocolate_, chocolate_+sizeof(chocolate_)/sizeof(*chocolate_)); 
	int _ = ; 
END
*/
}
// END CUT HERE