fca716a31c 2011-07-26 kinaba: #include <iostream> fca716a31c 2011-07-26 kinaba: #include <sstream> fca716a31c 2011-07-26 kinaba: #include <iomanip> fca716a31c 2011-07-26 kinaba: #include <vector> fca716a31c 2011-07-26 kinaba: #include <string> fca716a31c 2011-07-26 kinaba: #include <map> fca716a31c 2011-07-26 kinaba: #include <set> fca716a31c 2011-07-26 kinaba: #include <algorithm> fca716a31c 2011-07-26 kinaba: #include <numeric> fca716a31c 2011-07-26 kinaba: #include <iterator> fca716a31c 2011-07-26 kinaba: #include <functional> fca716a31c 2011-07-26 kinaba: #include <complex> fca716a31c 2011-07-26 kinaba: #include <queue> fca716a31c 2011-07-26 kinaba: #include <stack> fca716a31c 2011-07-26 kinaba: #include <cmath> fca716a31c 2011-07-26 kinaba: #include <cassert> fca716a31c 2011-07-26 kinaba: #include <cstring> fca716a31c 2011-07-26 kinaba: using namespace std; fca716a31c 2011-07-26 kinaba: typedef long long LL; fca716a31c 2011-07-26 kinaba: typedef complex<double> CMP; fca716a31c 2011-07-26 kinaba: fca716a31c 2011-07-26 kinaba: static const int MODVAL = 1000000009; fca716a31c 2011-07-26 kinaba: fca716a31c 2011-07-26 kinaba: class YetAnotherIncredibleMachine { public: fca716a31c 2011-07-26 kinaba: int countWays(vector <int> platformMount, vector <int> platformLength, vector <int> balls) fca716a31c 2011-07-26 kinaba: { fca716a31c 2011-07-26 kinaba: LL total = 1; fca716a31c 2011-07-26 kinaba: for(int p=0; p<platformLength.size(); ++p) fca716a31c 2011-07-26 kinaba: { fca716a31c 2011-07-26 kinaba: vector< pair<int,int> > q; fca716a31c 2011-07-26 kinaba: int len = platformLength[p]; fca716a31c 2011-07-26 kinaba: int pos = platformMount[p]; fca716a31c 2011-07-26 kinaba: q.push_back( make_pair(pos-len, pos) ); fca716a31c 2011-07-26 kinaba: for(int i=0; i<balls.size(); ++i) fca716a31c 2011-07-26 kinaba: avoid( balls[i], q, len ); fca716a31c 2011-07-26 kinaba: fca716a31c 2011-07-26 kinaba: int cnt = 0; fca716a31c 2011-07-26 kinaba: for(int i=0; i<q.size(); ++i) fca716a31c 2011-07-26 kinaba: cnt += q[i].second - q[i].first + 1; fca716a31c 2011-07-26 kinaba: total = total * cnt % MODVAL; fca716a31c 2011-07-26 kinaba: } fca716a31c 2011-07-26 kinaba: return int(total); fca716a31c 2011-07-26 kinaba: } fca716a31c 2011-07-26 kinaba: fca716a31c 2011-07-26 kinaba: void avoid(int x, vector< pair<int,int> >& q, int len) fca716a31c 2011-07-26 kinaba: { fca716a31c 2011-07-26 kinaba: vector< pair<int,int> > q2; fca716a31c 2011-07-26 kinaba: for(int i=0; i<q.size(); ++i) fca716a31c 2011-07-26 kinaba: if( q[i].second+len < x || x < q[i].first ) fca716a31c 2011-07-26 kinaba: q2.push_back( q[i] ); fca716a31c 2011-07-26 kinaba: else { fca716a31c 2011-07-26 kinaba: int L = q[i].first; fca716a31c 2011-07-26 kinaba: int R = q[i].second; fca716a31c 2011-07-26 kinaba: if( L<=x-len-1 ) fca716a31c 2011-07-26 kinaba: q2.push_back( make_pair(L, x-len-1) ); fca716a31c 2011-07-26 kinaba: if( x+1<=R ) fca716a31c 2011-07-26 kinaba: q2.push_back( make_pair(x+1, R) ); fca716a31c 2011-07-26 kinaba: } fca716a31c 2011-07-26 kinaba: q.swap(q2); fca716a31c 2011-07-26 kinaba: } fca716a31c 2011-07-26 kinaba: }; fca716a31c 2011-07-26 kinaba: fca716a31c 2011-07-26 kinaba: // BEGIN CUT HERE fca716a31c 2011-07-26 kinaba: #include <ctime> fca716a31c 2011-07-26 kinaba: double start_time; string timer() fca716a31c 2011-07-26 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } fca716a31c 2011-07-26 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) fca716a31c 2011-07-26 kinaba: { os << "{ "; fca716a31c 2011-07-26 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) fca716a31c 2011-07-26 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } fca716a31c 2011-07-26 kinaba: void verify_case(const int& Expected, const int& Received) { fca716a31c 2011-07-26 kinaba: bool ok = (Expected == Received); fca716a31c 2011-07-26 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; fca716a31c 2011-07-26 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } fca716a31c 2011-07-26 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); fca716a31c 2011-07-26 kinaba: #define END verify_case(_, YetAnotherIncredibleMachine().countWays(platformMount, platformLength, balls));} fca716a31c 2011-07-26 kinaba: int main(){ fca716a31c 2011-07-26 kinaba: fca716a31c 2011-07-26 kinaba: CASE(0) fca716a31c 2011-07-26 kinaba: int platformMount_[] = {7}; fca716a31c 2011-07-26 kinaba: vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); fca716a31c 2011-07-26 kinaba: int platformLength_[] = {10}; fca716a31c 2011-07-26 kinaba: vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); fca716a31c 2011-07-26 kinaba: int balls_[] = {3,4}; fca716a31c 2011-07-26 kinaba: vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); fca716a31c 2011-07-26 kinaba: int _ = 3; fca716a31c 2011-07-26 kinaba: END fca716a31c 2011-07-26 kinaba: CASE(1) fca716a31c 2011-07-26 kinaba: int platformMount_[] = {1,4}; fca716a31c 2011-07-26 kinaba: vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); fca716a31c 2011-07-26 kinaba: int platformLength_[] = {3,3}; fca716a31c 2011-07-26 kinaba: vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); fca716a31c 2011-07-26 kinaba: int balls_[] = {2,7}; fca716a31c 2011-07-26 kinaba: vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); fca716a31c 2011-07-26 kinaba: int _ = 1; fca716a31c 2011-07-26 kinaba: END fca716a31c 2011-07-26 kinaba: CASE(2) fca716a31c 2011-07-26 kinaba: int platformMount_[] = {4,4,4}; fca716a31c 2011-07-26 kinaba: vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); fca716a31c 2011-07-26 kinaba: int platformLength_[] = {10,9,8}; fca716a31c 2011-07-26 kinaba: vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); fca716a31c 2011-07-26 kinaba: int balls_[] = {1,100}; fca716a31c 2011-07-26 kinaba: vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); fca716a31c 2011-07-26 kinaba: int _ = 27; fca716a31c 2011-07-26 kinaba: END fca716a31c 2011-07-26 kinaba: CASE(3) fca716a31c 2011-07-26 kinaba: int platformMount_[] = {0}; fca716a31c 2011-07-26 kinaba: vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); fca716a31c 2011-07-26 kinaba: int platformLength_[] = {1}; fca716a31c 2011-07-26 kinaba: vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); fca716a31c 2011-07-26 kinaba: int balls_[] = {0}; fca716a31c 2011-07-26 kinaba: vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); fca716a31c 2011-07-26 kinaba: int _ = 0; fca716a31c 2011-07-26 kinaba: END fca716a31c 2011-07-26 kinaba: CASE(4) fca716a31c 2011-07-26 kinaba: int platformMount_[] = {100, -4215, 251}; fca716a31c 2011-07-26 kinaba: vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); fca716a31c 2011-07-26 kinaba: int platformLength_[] = {400, 10000, 2121}; fca716a31c 2011-07-26 kinaba: vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); fca716a31c 2011-07-26 kinaba: int balls_[] = {5000, 2270, 8512, 6122}; fca716a31c 2011-07-26 kinaba: vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); fca716a31c 2011-07-26 kinaba: int _ = 250379170; fca716a31c 2011-07-26 kinaba: END fca716a31c 2011-07-26 kinaba: /* fca716a31c 2011-07-26 kinaba: CASE(5) fca716a31c 2011-07-26 kinaba: int platformMount_[] = ; fca716a31c 2011-07-26 kinaba: vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); fca716a31c 2011-07-26 kinaba: int platformLength_[] = ; fca716a31c 2011-07-26 kinaba: vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); fca716a31c 2011-07-26 kinaba: int balls_[] = ; fca716a31c 2011-07-26 kinaba: vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); fca716a31c 2011-07-26 kinaba: int _ = ; fca716a31c 2011-07-26 kinaba: END fca716a31c 2011-07-26 kinaba: CASE(6) fca716a31c 2011-07-26 kinaba: int platformMount_[] = ; fca716a31c 2011-07-26 kinaba: vector <int> platformMount(platformMount_, platformMount_+sizeof(platformMount_)/sizeof(*platformMount_)); fca716a31c 2011-07-26 kinaba: int platformLength_[] = ; fca716a31c 2011-07-26 kinaba: vector <int> platformLength(platformLength_, platformLength_+sizeof(platformLength_)/sizeof(*platformLength_)); fca716a31c 2011-07-26 kinaba: int balls_[] = ; fca716a31c 2011-07-26 kinaba: vector <int> balls(balls_, balls_+sizeof(balls_)/sizeof(*balls_)); fca716a31c 2011-07-26 kinaba: int _ = ; fca716a31c 2011-07-26 kinaba: END fca716a31c 2011-07-26 kinaba: */ fca716a31c 2011-07-26 kinaba: } fca716a31c 2011-07-26 kinaba: // END CUT HERE