Artifact Content
Not logged in

Artifact 5d045ee47ad32484dd7a5e5da8368ed91950aedf


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

class ColorfulDecoration { public:
	int getMaximum(vector <int> xa, vector <int> ya, vector <int> xb, vector <int> yb) 
	{
		int L=0, R=1000000001;
		while( R-L>=2 )
		{
			int C = (L+R)/2;
			(canPlace(C, xa, ya, xb, yb)?L:R) = C;
		}
		return L;
	}

	typedef vector< vector<int> > graph;

	bool canPlace(int C, vector <int> xa, vector <int> ya, vector <int> xb, vector <int> yb)
	{
		int N = xa.size();

		graph G(2*N);
		for(int i=0; i<N; ++i) {
			for(int j=0; j<N; ++j) if(i!=j)
				if( !ok(C, xa[i], ya[i], xa[j], ya[j]) )
					G[i].push_back(N+j);
			for(int j=0; j<N; ++j) if(i!=j)
				if( !ok(C, xa[i], ya[i], xb[j], yb[j]) )
					G[i].push_back(j);
			for(int j=0; j<N; ++j) if(i!=j)
				if( !ok(C, xb[i], yb[i], xa[j], ya[j]) )
					G[N+i].push_back(N+j);
			for(int j=0; j<N; ++j) if(i!=j)
				if( !ok(C, xb[i], yb[i], xb[j], yb[j]) )
					G[N+i].push_back(j);
		}

		for(int i=0; i<N; ++i)
			if( reachable(G,i,N+i) && reachable(G,N+i,i) )
				return false;
		return true;
	}

	bool reachable(graph& G, int s, int d)
	{
		set<int> V;
		queue<int> Q;
		Q.push(s);
		V.insert(s);
		while( !Q.empty() ) {
			int v = Q.front(); Q.pop();
			for(int i=0; i<G[v].size(); ++i) {
				int u = G[v][i];
				if( u == d )
					return true;
				if( !V.count(u) )
					V.insert(u), Q.push(u);
			}
		}
		return false;
	}

	bool ok(int C, int x1, int y1, int x2, int y2)
	{
		return C <= max(abs(x1-x2), abs(y1-y2));
	}
};

// 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(_, ColorfulDecoration().getMaximum(xa, ya, xb, yb));}
int main(){

CASE(0)
	int xa_[] = { 10,  0,  7 };
	  vector <int> xa(xa_, xa_+sizeof(xa_)/sizeof(*xa_)); 
	int ya_[] = {  0, 19,  6 };
	  vector <int> ya(ya_, ya_+sizeof(ya_)/sizeof(*ya_)); 
	int xb_[] = { 20, 10, 25 };
	  vector <int> xb(xb_, xb_+sizeof(xb_)/sizeof(*xb_)); 
	int yb_[] = { 20, 35, 25 };
	  vector <int> yb(yb_, yb_+sizeof(yb_)/sizeof(*yb_)); 
	int _ = 19; 
END
CASE(1)
	int xa_[] = { 464, 20 };
	  vector <int> xa(xa_, xa_+sizeof(xa_)/sizeof(*xa_)); 
	int ya_[] = { 464, 10 };
	  vector <int> ya(ya_, ya_+sizeof(ya_)/sizeof(*ya_)); 
	int xb_[] = { 464,  3 };
	  vector <int> xb(xb_, xb_+sizeof(xb_)/sizeof(*xb_)); 
	int yb_[] = { 464, 16 };
	  vector <int> yb(yb_, yb_+sizeof(yb_)/sizeof(*yb_)); 
	int _ = 461; 
END
CASE(2)
	int xa_[] = { 0, 0, 1, 1 };
	  vector <int> xa(xa_, xa_+sizeof(xa_)/sizeof(*xa_)); 
	int ya_[] = { 0, 0, 1, 1 };
	  vector <int> ya(ya_, ya_+sizeof(ya_)/sizeof(*ya_)); 
	int xb_[] = { 1, 1, 0, 0 };
	  vector <int> xb(xb_, xb_+sizeof(xb_)/sizeof(*xb_)); 
	int yb_[] = { 1, 1, 0, 0 };
	  vector <int> yb(yb_, yb_+sizeof(yb_)/sizeof(*yb_)); 
	int _ = 0; 
END
CASE(3)
	int xa_[] = { 0, 3, 0, 5, 6 };
	  vector <int> xa(xa_, xa_+sizeof(xa_)/sizeof(*xa_)); 
	int ya_[] = { 1, 6, 0, 8, 5 };
	  vector <int> ya(ya_, ya_+sizeof(ya_)/sizeof(*ya_)); 
	int xb_[] = { 6, 1, 7, 4, 7 };
	  vector <int> xb(xb_, xb_+sizeof(xb_)/sizeof(*xb_)); 
	int yb_[] = { 5, 9, 2, 8, 9 };
	  vector <int> yb(yb_, yb_+sizeof(yb_)/sizeof(*yb_)); 
	int _ = 3; 
END
CASE(4)
	int xa_[] = { 1000000000, 0 };
	  vector <int> xa(xa_, xa_+sizeof(xa_)/sizeof(*xa_)); 
	int ya_[] = { 0, 1000000000 };
	  vector <int> ya(ya_, ya_+sizeof(ya_)/sizeof(*ya_)); 
	int xb_[] = { 0, 1000000000 };
	  vector <int> xb(xb_, xb_+sizeof(xb_)/sizeof(*xb_)); 
	int yb_[] = { 0, 1000000000 };
	  vector <int> yb(yb_, yb_+sizeof(yb_)/sizeof(*yb_)); 
	int _ = 1000000000; 
END
CASE(5)
	int xa_[] = {0,0};
	  vector <int> xa(xa_, xa_+sizeof(xa_)/sizeof(*xa_)); 
	int ya_[] = {0,0};
	  vector <int> ya(ya_, ya_+sizeof(ya_)/sizeof(*ya_)); 
	int xb_[] = {0,0};
	  vector <int> xb(xb_, xb_+sizeof(xb_)/sizeof(*xb_)); 
	int yb_[] = {0,0};
	  vector <int> yb(yb_, yb_+sizeof(yb_)/sizeof(*yb_)); 
	int _ = 0; 
END
CASE(6)
	int xa_[] = {0,0};
	  vector <int> xa(xa_, xa_+sizeof(xa_)/sizeof(*xa_)); 
	int ya_[] = {0,0};
	  vector <int> ya(ya_, ya_+sizeof(ya_)/sizeof(*ya_)); 
	int xb_[] = {1,1};
	  vector <int> xb(xb_, xb_+sizeof(xb_)/sizeof(*xb_)); 
	int yb_[] = {1,1};
	  vector <int> yb(yb_, yb_+sizeof(yb_)/sizeof(*yb_)); 
	int _ = 1; 
END
CASE(7)
	int xa_[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9};
	  vector <int> xa(xa_, xa_+sizeof(xa_)/sizeof(*xa_)); 
	int ya_[] = {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10};
	  vector <int> ya(ya_, ya_+sizeof(ya_)/sizeof(*ya_)); 
	int xb_[] = {2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11};
	  vector <int> xb(xb_, xb_+sizeof(xb_)/sizeof(*xb_)); 
	int yb_[] = {3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11,12};
	  vector <int> yb(yb_, yb_+sizeof(yb_)/sizeof(*yb_)); 
	int _ = -1; 
END

}
// END CUT HERE