Artifact Content
Not logged in

Artifact 9fc4b0d6d011b0bd96022064f292ca3ce7f2b039


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

typedef int           vert;
typedef vert          edge;
typedef vector<edge>  edges;
typedef vector<edges> graph;

bool augment( graph& G, int v, vector<vert>& matchTo, bool visited[] )
{
	for(int i=0; i<G[v].size(); ++i) {
		vert u = G[v][i];
		if( visited[u] ) continue;
		visited[u] = true;

		if( matchTo[u]<0 || augment(G, matchTo[u], matchTo, visited) )
			{ matchTo[v]=u, matchTo[u]=v; return true; }
	}
	return false;
}

template<int NV>
int biMatch( graph& G, int L ) // [0,L):left, [L,?):right
{
	vector<vert> matchTo(G.size(), -1);
	int ans = 0;
	for(vert v=0; v<L; ++v) {
		bool visited[NV] = {};
		if( augment(G, v, matchTo, visited) )
			++ans;
	}
	return ans;
}

class PointyWizardHats { public:
	int getNumHats(vector <int> topHeight, vector <int> topRadius, vector <int> bottomHeight, vector <int> bottomRadius)
	{
		int L = topHeight.size();
		int R = bottomHeight.size();
		graph G(L+R);
		for(int i=0; i<L; ++i)
			for(int k=0; k<R; ++k)
				if( ok(topHeight[i], topRadius[i], bottomHeight[k], bottomRadius[k]) )
					G[i].push_back(L+k);
		return biMatch<100>(G, L);
	}

	bool ok(int th, int tr, int bh, int br)
	{
		if( th*br > bh*tr ) {
			return br > tr;
		}
		return false;
	}
};

// 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(_, PointyWizardHats().getNumHats(topHeight, topRadius, bottomHeight, bottomRadius));}
int main(){

CASE(0)
	int topHeight_[] = {30};
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = {3};
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = {3};
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = {30};
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = 1; 
END
CASE(1)
	int topHeight_[] = {4,4};
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = {4,3};
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = {5,12};
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = {5,4};
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = 1; 
END
CASE(2)
	int topHeight_[] = {3};
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = {3};
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = {1,1};
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = {2,4};
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = 1; 
END
CASE(3)
	int topHeight_[] = {10,10};
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = {2,5};
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = {2,9};
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = {3,6};
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = 2; 
END
CASE(4)
	int topHeight_[] = {3,4,5};
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = {5,4,3};
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = {3,4,5};
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = {3,8,5};
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = 2; 
END
CASE(5)
	int topHeight_[] = {1,2,3,4,5};
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = {2,3,4,5,6};
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = {2,3,4,5,6};
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = {1,2,3,4,5};
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = 0; 
END
CASE(6)
	int topHeight_[] = {123,214,232,323,342,343};
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = {123,123,232,123,323,434};
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = {545,322,123,545,777,999};
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = {323,443,123,656,767,888};
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = 5; 
END
CASE(7)
	int topHeight_[] = {999,999,999,10000,10000,10000};
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = {10000,10000,10000,1,2,3};
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = {2324,2323,234,5454,323,232};
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = {1,2,3222,434,5454,23};
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = 3; 
END
/*
CASE(8)
	int topHeight_[] = ;
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = ;
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = ;
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = ;
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = ; 
END
CASE(9)
	int topHeight_[] = ;
	  vector <int> topHeight(topHeight_, topHeight_+sizeof(topHeight_)/sizeof(*topHeight_)); 
	int topRadius_[] = ;
	  vector <int> topRadius(topRadius_, topRadius_+sizeof(topRadius_)/sizeof(*topRadius_)); 
	int bottomHeight_[] = ;
	  vector <int> bottomHeight(bottomHeight_, bottomHeight_+sizeof(bottomHeight_)/sizeof(*bottomHeight_)); 
	int bottomRadius_[] = ;
	  vector <int> bottomRadius(bottomRadius_, bottomRadius_+sizeof(bottomRadius_)/sizeof(*bottomRadius_)); 
	int _ = ; 
END
*/
}
// END CUT HERE