Artifact Content
Not logged in

Artifact ab9100cd4e760130989602cf116921dc364b9b02


#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 <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class Over9000Rocks { public:
	int countPossibilities(vector <int> lowerBound, vector <int> upperBound)
	{
		vector< pair<int,bool> > ev;
		const int MIN = 9001;
		const int N = lowerBound.size();
		for(int mask=1; mask<(1<<N); ++mask)
		{
			int lo=0, hi=0;
			for(int i=0; i<N; ++i)
				if( mask & (1<<i) ) {
					lo += lowerBound[i];
					hi += upperBound[i];
				}
			if(hi<MIN)
				continue;
			lo = max(lo, MIN);
			ev.push_back( make_pair(lo,true) );
			ev.push_back( make_pair(hi+1,false) );
		}
		sort(ev.begin(), ev.end());
		int nest = 0;
		int entered = -1;
		int total = 0;
		for(int k=0; k<ev.size(); ++k)
		{
			int x = ev[k].first;
			bool in = ev[k].second;
			if( nest == 0 ) {
				if( in )
					entered = x;
			} else if( nest == 1 ) {
				if( !in )
					total += (x - entered);
			}
			if(in) nest++; else nest--;
		}
		return total;
	}
};

// 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(_, Over9000Rocks().countPossibilities(lowerBound, upperBound));}
int main(){

CASE(0)
	int lowerBound_[] = {9000};
	  vector <int> lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); 
	int upperBound_[] = {9001};
	  vector <int> upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); 
	int _ = 1; 
END
CASE(1)
	int lowerBound_[] = {9000, 1, 10};
	  vector <int> lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); 
	int upperBound_[] = {9000, 2, 20};
	  vector <int> upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); 
	int _ = 15; 
END
CASE(2)
	int lowerBound_[] = {1001, 2001, 3001, 3001};
	  vector <int> lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); 
	int upperBound_[] = {1003, 2003, 3003, 3003};
	  vector <int> upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); 
	int _ = 9; 
END
CASE(3)
	int lowerBound_[] = {9000,90000,1,10};
	  vector <int> lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); 
	int upperBound_[] = {9000,90000,3,15};
	  vector <int> upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); 
	int _ = 38; 
END
CASE(4)
	int lowerBound_[] = {1,1,1,1,1,1};
	  vector <int> lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); 
	int upperBound_[] = {3,4,5,6,7,8};
	  vector <int> upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); 
	int _ = 0; 
END
CASE(5)
	int lowerBound_[] = {242,7393,3738,2594,3051,7711,3386,4363,6035,4752,5384,7607,5702,2226,7792};
	  vector <int> lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); 
	int upperBound_[] = {9138,9120,9027,9185,9081,9114,9044,9089,9178,9103,9089,9026,9129,9050,9173};
	  vector <int> upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); 
	int _ = -1; 
END
CASE(6)
	int lowerBound_[] = {9001};
	  vector <int> lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); 
	  int upperBound_[] = {9002};
	  vector <int> upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); 
	int _ = 2; 
END
CASE(7)
	int lowerBound_[] = {9000, 1, 2, 3};
	  vector <int> lowerBound(lowerBound_, lowerBound_+sizeof(lowerBound_)/sizeof(*lowerBound_)); 
	  int upperBound_[] = {9000, 1, 2, 3};
	  vector <int> upperBound(upperBound_, upperBound_+sizeof(upperBound_)/sizeof(*upperBound_)); 
	int _ = 10; 
END

}
// END CUT HERE