Artifact Content
Not logged in

Artifact 17eca4992b85996a09ffd306bdb34027720a22f7


#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 BallsSeparating { public:
	int minOperations(vector <int> red, vector <int> green, vector <int> blue)
	{
		int best = 1<<30;
		int N = red.size();

		if(N<=2)
			return -1;
		for(int R=0; R<N; ++R)
		for(int G=0; G<N; ++G) if(G!=R)
		for(int B=0; B<N; ++B) if(B!=G && B!=R)
		{
			int c = 0;
			for(int i=0; i<N; ++i)
			{
				int gb =  green[i] + blue[i];
				int br = blue[i] + red[i];
				int rg = red[i] + green[i];
				if(i==R) c += gb;
				else if(i==B) c += rg;
				else if(i==G) c += br;
				else c += min(gb, min(rg,br));
			}
			best = min(best, c);
		}
		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(_, BallsSeparating().minOperations(red, green, blue));}
int main(){

CASE(0)
	int red_[] = {1, 1, 1};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int green_[] = {1, 1, 1};
	  vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 
	int blue_[] = {1, 1, 1};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = 6; 
END
CASE(1)
	int red_[] = {5};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int green_[] = {6};
	  vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 
	int blue_[] = {8};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = -1; 
END
CASE(2)
	int red_[] = {4, 6, 5, 7};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int green_[] = {7, 4, 6, 3};
	  vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 
	int blue_[] = {6, 5, 3, 8};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = 37; 
END
CASE(3)
	int red_[] = {7, 12, 9, 9, 7};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int green_[] = {7, 10, 8, 8, 9};
	  vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 
	int blue_[] = {8, 9, 5, 6, 13};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = 77; 
END
CASE(4)
	int red_[] = {842398, 491273, 958925, 849859, 771363, 67803, 184892, 391907, 256150, 75799};
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int green_[] = {268944, 342402, 894352, 228640, 903885, 908656, 414271, 292588, 852057, 889141};
	  vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 
	int blue_[] = {662939, 340220, 600081, 390298, 376707, 372199, 435097, 40266, 145590, 505103};
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = 7230607; 
END
	/*
CASE(5)
	int red_[] = ;
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int green_[] = ;
	  vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 
	int blue_[] = ;
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = ; 
END
CASE(6)
	int red_[] = ;
	  vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 
	int green_[] = ;
	  vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 
	int blue_[] = ;
	  vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 
	int _ = ; 
END
	*/
}
// END CUT HERE