Artifact Content
Not logged in

Artifact 0fb66fe6be1bd22dba8e1d322297592b020b8a49


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

class ColoringRectangle { public:
	int chooseDisks(int width, int height, vector <int> red, vector <int> blue) 
	{
		vector<double> R;
		for(int i=0; i<red.size(); ++i) {
			double r = red[i]/2.0;
			if( r < height/2 )
				continue;
			R.push_back( sqrt(r*r - (height/2.0)*(height/2.0))*2 );
		}
		vector<double> B;
		for(int i=0; i<blue.size(); ++i) {
			double r = blue[i]/2.0;
			if( r < height/2 )
				continue;
			B.push_back( sqrt(r*r - (height/2.0)*(height/2.0))*2 );
		}
		sort(R.rbegin(), R.rend());
		sort(B.rbegin(), B.rend());

		int m = f(R, B, width);
		int n = f(B, R, width);
		int a = min(m,n);
		if( a == INT_MAX )
			return -1;
		return a;
	}
	int f(vector<double>& R, vector<double>& B, double W) {
		double w = 0;
		for(int i=0 ;; ++i) {
			if( i%2 == 0 ) {
				if( i/2>=R.size() )
					return INT_MAX;
				w += R[i/2];
				if( W <= w )
					return i+1;
			} else {
				if( i/2>=B.size() )
					return INT_MAX;
				w += B[i/2];
				if( W <= w )
					return i+1;
			}
		}
	}
};

// 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(_, ColoringRectangle().chooseDisks(width, height, red, blue));}
int main(){

CASE(0)
	int width = 11; 
	int height = 3; 
	int red_[] = {5,5};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int blue_[] = {2,5};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = 3; 
END
CASE(1)
	int width = 30; 
	int height = 5; 
	int red_[] = {4,10,7,8,10};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int blue_[] = {5,6,11,7,5};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = 4; 
END
CASE(2)
	int width = 16; 
	int height = 4; 
	int red_[] = {6,5,7};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int blue_[] = {5};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = -1; 
END
CASE(3)
	int width = 4; 
	int height = 4; 
	int red_[] = {5};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int blue_[] = {6};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = 1; 
END
CASE(4)
	int width = 6; 
	int height = 2; 
	int red_[] = {6,6};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int blue_[] = {2};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = 3; 
END
CASE(5)
	int width = 16; 
	int height = 13; 
	int red_[] = {20};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int blue_[] = {20};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = -1; 
END
/*
CASE(6)
	int width = ; 
	int height = ; 
	int red_[] = ;
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int blue_[] = ;
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = ; 
END
*/
}
// END CUT HERE