Artifact Content
Not logged in

Artifact ba901c83080df3e4bb2f679cc02b937b163f63bb


#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;

class DrawingPointsDivOne { public:
	int maxSteps(vector <int> x, vector <int> y)
	{
		static const int INF = 300;
		int L=0, R=INF+1;
		while(R-L>1) {
			int C = (L+R)/2;
			(possible(x,y,C) ? L : R) = C;
		}
		return L==INF ? -1 : L;
	}

	bool possible(const vector<int>& x, const vector<int>& y, int C)
	{
		int N = x.size();
		int Z = C+10+280+C+10;
		int MID = C+10+140;
		vector<int> m(Z*Z);

		// paint
		for(int i=0; i<N; ++i) {
			int yy = MID+y[i]*2;
			int xx = MID+x[i]*2;
			m[ (yy+C  )*Z+(xx+C  ) ] += 1;
			m[ (yy-C-2)*Z+(xx+C  ) ] -= 1;
			m[ (yy+C  )*Z+(xx-C-2) ] -= 1;
			m[ (yy-C-2)*Z+(xx-C-2) ] += 1;
		}

		// sum
		for(int y=Z-3; y>=0; --y)
		for(int x=Z-3; x>=0; --x)
			m[y*Z+x] += m[(y+2)*Z+x]+m[y*Z+(x+2)]-m[(y+2)*Z+(x+2)];

		for(int y=0; y<Z; ++y) for(int x=0; x<Z; ++x) m[y*Z+x] = !!m[y*Z+x];

		// sum
		for(int y=Z-3; y>=0; --y)
		for(int x=Z-3; x>=0; --x)
			m[y*Z+x] += m[(y+2)*Z+x]+m[y*Z+(x+2)]-m[(y+2)*Z+(x+2)];

		// count
		int cnt = 0;
		int S = (MID&1);
		for(int yy=S; yy<Z; yy+=2)
		for(int xx=S; xx<Z; xx+=2)
		if(yy+C+2<Z && xx+C+2<Z && yy-C>=0 && xx-C>=0) {
			int s =
				+m[ (yy+C+2)*Z+(xx+C+2) ]
				-m[ (yy-C  )*Z+(xx+C+2) ]
				-m[ (yy+C+2)*Z+(xx-C  ) ]
				+m[ (yy-C  )*Z+(xx-C  ) ];
			if(s==(C+1)*(C+1))
				++cnt;
		}
		return cnt == N;
	}
};

// 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(_, DrawingPointsDivOne().maxSteps(x, y));}
int main(){

CASE(0)
	int x_[] = {0, 3};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {0, 0};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = 1; 
END
CASE(1)
	int x_[] = {0,2};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {0,0};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = 0; 
END
CASE(2)
	int x_[] = {-70};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {3};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = -1; 
END
CASE(3)
	int x_[] = {-41,-40,1,-11,-32,-7,24,-11,49,-15,-22,20,-8,54,54,69,16,-30,36,-6,-30,40,64,20,-66,
 -37,-33,-18,-35,36,9,61,-43,45,5,60,-8,-58,65,-66,41,12,34,-11,-57,-38,46,63,-55,3};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {5,-24,-2,-4,23,14,1,70,-26,45,15,48,32,-41,54,-47,-67,-46,-9,-53,54,28,-61,11,53,68,
 -33,62,37,-8,-17,-17,48,19,-49,56,-41,16,17,-50,28,59,10,50,23,-16,56,31,-70,-44};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = 9; 
END
/*
CASE(4)
	int x_[] = ;
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = ;
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = ; 
END
CASE(5)
	int x_[] = ;
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = ;
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = ; 
END
*/
}
// END CUT HERE