Artifact Content
Not logged in

Artifact 1e07ad54dbeb74d6485ddf5df307fed6a8842191


#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 ElectionFraudDiv1 { public:
	int MinimumVoters(vector <int> percentages)
	{
		for(int voter=1; voter<=100000; ++voter)
			if(possible(voter, percentages))
				return voter;
		return -1;
	}

	bool possible(int V, const vector<int>& P)
	{
		int L=0, R=0;
		for(int i=0; i<P.size(); ++i) 
		{
			int p = P[i];

			// p-0.5 <= x/V*100 < p+0.5
			// 2p-1  <= x/V*200 < 2p+1

			int ll = (2*p-1)*V;
			int rr = (2*p+1)*V;

			// ll <= x*200 < rr

			int l = max(0, (ll+199)/200);
			int r = min(V, rr/200 - (rr%200 ? 0 : 1));

			// l <= x <= r

			if( l <= r )
				L+=l, R+=r;
			else
				return false;
		}
		return L<=V && V<=R;
	}
};

// 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(_, ElectionFraudDiv1().MinimumVoters(percentages));}
int main(){

CASE(0)
	int percentages_[] = {33, 33, 33};
	  vector <int> percentages(percentages_, percentages_+sizeof(percentages_)/sizeof(*percentages_)); 
	int _ = 3; 
END
CASE(1)
	int percentages_[] = {29, 29, 43};
	  vector <int> percentages(percentages_, percentages_+sizeof(percentages_)/sizeof(*percentages_)); 
	int _ = 7; 
END
CASE(2)
	int percentages_[] = {12, 12, 12, 12, 12, 12, 12, 12};
	  vector <int> percentages(percentages_, percentages_+sizeof(percentages_)/sizeof(*percentages_)); 
	int _ = -1; 
END
CASE(3)
	int percentages_[] = {13, 13, 13, 13, 13, 13, 13, 13};
	  vector <int> percentages(percentages_, percentages_+sizeof(percentages_)/sizeof(*percentages_)); 
	int _ = 8; 
END
CASE(4)
	int percentages_[] = {0, 1, 100};
	  vector <int> percentages(percentages_, percentages_+sizeof(percentages_)/sizeof(*percentages_)); 
	int _ = 200; 
END
CASE(5)
	int percentages_[] = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4};
	  vector <int> percentages(percentages_, percentages_+sizeof(percentages_)/sizeof(*percentages_)); 
	int _ = 97; 
END
/*
CASE(6)
	int percentages_[] = ;
	  vector <int> percentages(percentages_, percentages_+sizeof(percentages_)/sizeof(*percentages_)); 
	int _ = ; 
END
CASE(7)
	int percentages_[] = ;
	  vector <int> percentages(percentages_, percentages_+sizeof(percentages_)/sizeof(*percentages_)); 
	int _ = ; 
END
*/
}
// END CUT HERE