Artifact Content
Not logged in

Artifact 88a9946483caf8ed47883aa75b4fded0739408f1


#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;

double outer_prod(const CMP& a, const CMP& b) { return imag(conj(a)*b); }

bool point_in_polygon( vector<CMP>& ps, CMP p )
{
	bool in = false;
	for(int i=0; i<ps.size(); ++i) {
		CMP a = ps[i] - p;
		CMP b = ps[(i+1)%ps.size()] - p;
		if(a.imag() > b.imag()) swap(a,b);
		if(a.imag()<=0 && 0<b.imag()) {
			if( outer_prod(a,b) < 0 )
				in = !in;
		}
	}
	return in;
}

class RedAndBluePoints { public:
	int find(vector <int> blueX, vector <int> blueY, vector <int> redX, vector <int> redY)
	{
		const int B = blueX.size();
		const int R = redX.size();

		int best = 0;
		for(int b_use=0; b_use<B; ++b_use)
		{
			vector<vector<int>> G(B);
			for(int b1=0; b1<B; ++b1) if(b1 != b_use)
			for(int b2=b1+1; b2<B; ++b2) if(b2 != b_use) {
				bool bad = false;

				vector<CMP> poly;
				poly.emplace_back(blueX[b_use], blueY[b_use]);
				poly.emplace_back(blueX[b1], blueY[b1]);
				poly.emplace_back(blueX[b2], blueY[b2]);
				for(int r=0; r<R; ++r)
					if(point_in_polygon(poly, CMP(redX[r], redY[r])))
						{ bad=true; break; }

				if(bad) {
					G[b1].push_back(b2);
					G[b2].push_back(b1);
				}
			}
			best = max(best, max_independent_set(G));
		}
		return best;
	}

	int max_independent_set(const vector<vector<int>>& G)
	{
		const int N = G.size();
		vector<LL> badmask(G.size());
		for(int v=0; v<N; ++v) {
			LL x = 1LL<<v;
			for(int u: G[v])
				x |= 1LL<<u;
			badmask[v] = x;
		}

		int best = 0;
		function<void(int,LL,int)> rec = [&](int v, LL rest, int cur) {
			if(best < cur)
				best = cur;
			if(rest == 0)
				return;
			if(cur + __builtin_popcountll(rest) <= best)
				return;

			LL r1 = rest &~ (1LL<<v);
			LL r2 = rest &~ badmask[v];
			if(rest & (1LL<<v)) {
				if(r1 != r2) rec(v+1, r1, cur);
				rec(v+1, r2, cur+1);
			} else {
				rec(v+1, r1, cur);
			}
		};
		rec(0, (1LL<<N)-1, 0);
		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(_, RedAndBluePoints().find(blueX, blueY, redX, redY));}
int main(){

CASE(0)
	int blueX_[] = {0,0,10,10};
	  vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 
	int blueY_[] = {0,10,0,10};
	  vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 
	int redX_[] = {100};
	  vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 
	int redY_[] = {120};
	  vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 
	int _ = 4; 
END
CASE(1)
	int blueX_[] = {0,0,10,10};
	  vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 
	int blueY_[] = {0,10,0,10};
	  vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 
	int redX_[] = {3};
	  vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 
	int redY_[] = {4};
	  vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 
	int _ = 3; 
END
CASE(2)
	int blueX_[] = {0,0,10,10};
	  vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 
	int blueY_[] = {0,10,0,10};
	  vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 
	int redX_[] = {3,6};
	  vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 
	int redY_[] = {2,7};
	  vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 
	int _ = 2; 
END
CASE(3)
	int blueX_[] = {0};
	  vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 
	int blueY_[] = {0};
	  vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 
	int redX_[] = {1};
	  vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 
	int redY_[] = {1};
	  vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 
	int _ = 1; 
END
CASE(4)
	int blueX_[] = {5, 6, 6};
	  vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 
	int blueY_[] = {9, 0, 5};
	  vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 
	int redX_[] = {7};
	  vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 
	int redY_[] = {6};
	  vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 
	int _ = 3; 
END
/*
CASE(5)
	int blueX_[] = ;
	  vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 
	int blueY_[] = ;
	  vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 
	int redX_[] = ;
	  vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 
	int redY_[] = ;
	  vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 
	int _ = ; 
END
CASE(6)
	int blueX_[] = ;
	  vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 
	int blueY_[] = ;
	  vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 
	int redX_[] = ;
	  vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 
	int redY_[] = ;
	  vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 
	int _ = ; 
END
*/
}
// END CUT HERE