Artifact Content
Not logged in

Artifact 5a7a82e56d0038edf49878302d0a5dc3ce304ab0


#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 UniformBoard { public:
	int getBoard(vector <string> board, int K)
	{
		const int N = board.size();

		int A=0, P=0;
		for(int y=0; y<N; ++y)
		for(int x=0; x<N; ++x) {
			if(board[y][x]=='P')++P;
			if(board[y][x]=='A')++A;
		}

		int best = 0;
		for(int y=0; y<N; ++y)
		for(int x=0; x<N; ++x)
		for(int yy=y+1; yy<=N; ++yy)
		for(int xx=x+1; xx<=N; ++xx)
		{
			int a=0, p=0;
			for(int i=y; i<yy; ++i)
			for(int k=x; k<xx; ++k) {
				if(board[i][k]=='P')++p;
				if(board[i][k]=='A')++a;
			}
			int move = calc(A,P,N*N-A-P,a,p,(yy-y)*(xx-x)-a-p);
			if(move<=K)
				best = max(best, (yy-y)*(xx-x));
		}
		return best;
	}

	int calc(int A, int P, int E, int a, int p, int e)
	{
		const int INF = 0x7ffffff;
		A -= a;
		P -= p;
		E -= e;

		if(e+p > A)
			return INF;

		int move = 0;
		if(e) {
			move += e;
			E += e;
			A -= e;
			a += e;
			e = 0;
		}
		if(p) {
			if(E == 0)
				return INF;
			move += 2*p;
		}
		return move;
	}
};

// 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(_, UniformBoard().getBoard(board, K));}
int main(){

CASE(0)
	string board_[] = {"AP",
 ".A"};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int K = 0; 
	int _ = 1; 
END
CASE(1)
	string board_[] = {"AP",
 ".A"};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int K = 1; 
	int _ = 2; 
END
CASE(2)
	string board_[] = {"PPP",
 "APA",
 "A.P"};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int K = 2; 
	int _ = 3; 
END
CASE(3)
	string board_[] = {"AAA",
 "PPP",
 "AAA"};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int K = 10; 
	int _ = 3; 
END
CASE(4)
	string board_[] = {"."};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int K = 1000; 
	int _ = 0; 
END
CASE(5)
	string board_[] = {"PPAAPA..AP",
 "PPA.APAP..",
 "..P.AA.PPP",
 "P.P..APAA.",
 "P.P..P.APA",
 "PPA..AP.AA",
 "APP..AAPAA",
 "P.P.AP...P",
 ".P.A.PAPPA",
 "..PAPAP..P"};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int K = 10; 
	int _ = 15; 
END
/*
CASE(6)
	string board_[] = ;
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int K = ; 
	int _ = ; 
END
CASE(7)
	string board_[] = ;
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int K = ; 
	int _ = ; 
END
*/
}
// END CUT HERE