Artifact Content
Not logged in

Artifact d303488aa62482096a57a38478a2f2fba35c69ca


#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>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const int MODVAL = 1000000009;

class YetAnotherIncredibleMachine { public:
	int countWays(vector <int> platformMount, vector <int> platformLength, vector <int> balls) 
	{
		LL total = 1;
		for(int p=0; p<platformLength.size(); ++p)
		{
			vector< pair<int,int> > q;
			int len = platformLength[p];
			int pos = platformMount[p];
			q.push_back( make_pair(pos-len, pos) );
			for(int i=0; i<balls.size(); ++i)
				avoid( balls[i], q, len );

			int cnt = 0;
			for(int i=0; i<q.size(); ++i)
				cnt += q[i].second - q[i].first + 1;
			total = total * cnt % MODVAL;
		}
		return int(total);
	}

	void avoid(int x, vector< pair<int,int> >& q, int len)
	{
		vector< pair<int,int> > q2;
		for(int i=0; i<q.size(); ++i)
			if( q[i].second+len < x || x < q[i].first )
				q2.push_back( q[i] );
			else {
				int L = q[i].first;
				int R = q[i].second;
				if( L<=x-len-1 )
					q2.push_back( make_pair(L, x-len-1) );
				if( x+1<=R )
					q2.push_back( make_pair(x+1, R) );
			}
		q.swap(q2);
	}
};

// 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(_, YetAnotherIncredibleMachine().countWays(platformMount, platformLength, balls));}
int main(){

CASE(0)
	int platformMount_[] = {7};
	  vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); 
	int platformLength_[] = {10};
	  vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); 
	int balls_[] = {3,4};
	  vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); 
	int _ = 3; 
END
CASE(1)
	int platformMount_[] = {1,4};
	  vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); 
	int platformLength_[] = {3,3};
	  vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); 
	int balls_[] = {2,7};
	  vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); 
	int _ = 1; 
END
CASE(2)
	int platformMount_[] = {4,4,4};
	  vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); 
	int platformLength_[] = {10,9,8};
	  vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); 
	int balls_[] = {1,100};
	  vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); 
	int _ = 27; 
END
CASE(3)
	int platformMount_[] = {0};
	  vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); 
	int platformLength_[] = {1};
	  vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); 
	int balls_[] = {0};
	  vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); 
	int _ = 0; 
END
CASE(4)
	int platformMount_[] = {100, -4215, 251};
	  vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); 
	int platformLength_[] = {400, 10000, 2121};
	  vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); 
	int balls_[] = {5000, 2270, 8512, 6122};
	  vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); 
	int _ = 250379170; 
END
/*
CASE(5)
	int platformMount_[] = ;
	  vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); 
	int platformLength_[] = ;
	  vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); 
	int balls_[] = ;
	  vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); 
	int _ = ; 
END
CASE(6)
	int platformMount_[] = ;
	  vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); 
	int platformLength_[] = ;
	  vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); 
	int balls_[] = ;
	  vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); 
	int _ = ; 
END
*/
}
// END CUT HERE