143923277f 2014-11-03 kinaba: #include <iostream> 143923277f 2014-11-03 kinaba: #include <sstream> 143923277f 2014-11-03 kinaba: #include <iomanip> 143923277f 2014-11-03 kinaba: #include <vector> 143923277f 2014-11-03 kinaba: #include <string> 143923277f 2014-11-03 kinaba: #include <map> 143923277f 2014-11-03 kinaba: #include <set> 143923277f 2014-11-03 kinaba: #include <algorithm> 143923277f 2014-11-03 kinaba: #include <numeric> 143923277f 2014-11-03 kinaba: #include <iterator> 143923277f 2014-11-03 kinaba: #include <functional> 143923277f 2014-11-03 kinaba: #include <complex> 143923277f 2014-11-03 kinaba: #include <queue> 143923277f 2014-11-03 kinaba: #include <stack> 143923277f 2014-11-03 kinaba: #include <cmath> 143923277f 2014-11-03 kinaba: #include <cassert> 143923277f 2014-11-03 kinaba: #include <tuple> 143923277f 2014-11-03 kinaba: using namespace std; 143923277f 2014-11-03 kinaba: typedef long long LL; 143923277f 2014-11-03 kinaba: typedef complex<double> CMP; 143923277f 2014-11-03 kinaba: 143923277f 2014-11-03 kinaba: const int MODVAL = 1000000007; 143923277f 2014-11-03 kinaba: 143923277f 2014-11-03 kinaba: class NarrowPassage2 { public: 143923277f 2014-11-03 kinaba: int count(vector <int> size, int maxSizeSum) 143923277f 2014-11-03 kinaba: { 143923277f 2014-11-03 kinaba: if(size.size() <= 1) 143923277f 2014-11-03 kinaba: return 1; 143923277f 2014-11-03 kinaba: 143923277f 2014-11-03 kinaba: int mi = min_element(size.begin(), size.end()) - size.begin(); 143923277f 2014-11-03 kinaba: 143923277f 2014-11-03 kinaba: int lm=mi; 143923277f 2014-11-03 kinaba: for(int k=mi-1; k>=0 && size[k]+size[mi]<=maxSizeSum; --k) 143923277f 2014-11-03 kinaba: lm = k; 143923277f 2014-11-03 kinaba: int rm=mi; 143923277f 2014-11-03 kinaba: for(int k=mi+1; k<size.size() && size[k]+size[mi]<=maxSizeSum; ++k) 143923277f 2014-11-03 kinaba: rm = k; 143923277f 2014-11-03 kinaba: 143923277f 2014-11-03 kinaba: size.erase(size.begin()+mi); 143923277f 2014-11-03 kinaba: return LL(rm-lm+1) * count(size, maxSizeSum) % MODVAL; 143923277f 2014-11-03 kinaba: } 143923277f 2014-11-03 kinaba: }; 143923277f 2014-11-03 kinaba: 143923277f 2014-11-03 kinaba: // BEGIN CUT HERE 143923277f 2014-11-03 kinaba: #include <ctime> 143923277f 2014-11-03 kinaba: double start_time; string timer() 143923277f 2014-11-03 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 143923277f 2014-11-03 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 143923277f 2014-11-03 kinaba: { os << "{ "; 143923277f 2014-11-03 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 143923277f 2014-11-03 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 143923277f 2014-11-03 kinaba: void verify_case(const int& Expected, const int& Received) { 143923277f 2014-11-03 kinaba: bool ok = (Expected == Received); 143923277f 2014-11-03 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 143923277f 2014-11-03 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 143923277f 2014-11-03 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 143923277f 2014-11-03 kinaba: #define END verify_case(_, NarrowPassage2().count(size, maxSizeSum));} 143923277f 2014-11-03 kinaba: int main(){ 143923277f 2014-11-03 kinaba: 143923277f 2014-11-03 kinaba: CASE(0) 143923277f 2014-11-03 kinaba: int size_[] = {1, 2, 3}; 143923277f 2014-11-03 kinaba: vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 143923277f 2014-11-03 kinaba: int maxSizeSum = 3; 143923277f 2014-11-03 kinaba: int _ = 2; 143923277f 2014-11-03 kinaba: END 143923277f 2014-11-03 kinaba: CASE(1) 143923277f 2014-11-03 kinaba: int size_[] = {1, 2, 3}; 143923277f 2014-11-03 kinaba: vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 143923277f 2014-11-03 kinaba: int maxSizeSum = 1000; 143923277f 2014-11-03 kinaba: int _ = 6; 143923277f 2014-11-03 kinaba: END 143923277f 2014-11-03 kinaba: CASE(2) 143923277f 2014-11-03 kinaba: int size_[] = {1, 2, 3}; 143923277f 2014-11-03 kinaba: vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 143923277f 2014-11-03 kinaba: int maxSizeSum = 4; 143923277f 2014-11-03 kinaba: int _ = 3; 143923277f 2014-11-03 kinaba: END 143923277f 2014-11-03 kinaba: CASE(3) 143923277f 2014-11-03 kinaba: int size_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1}; 143923277f 2014-11-03 kinaba: vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 143923277f 2014-11-03 kinaba: int maxSizeSum = 2; 143923277f 2014-11-03 kinaba: int _ = 227020758; 143923277f 2014-11-03 kinaba: END 143923277f 2014-11-03 kinaba: CASE(4) 143923277f 2014-11-03 kinaba: int size_[] = {2,4,6,1,3,5}; 143923277f 2014-11-03 kinaba: vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 143923277f 2014-11-03 kinaba: int maxSizeSum = 8; 143923277f 2014-11-03 kinaba: int _ = 60; 143923277f 2014-11-03 kinaba: END 143923277f 2014-11-03 kinaba: CASE(5) 143923277f 2014-11-03 kinaba: int size_[] = {1000000000}; 143923277f 2014-11-03 kinaba: vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 143923277f 2014-11-03 kinaba: int maxSizeSum = 1000000000; 143923277f 2014-11-03 kinaba: int _ = 1; 143923277f 2014-11-03 kinaba: END 143923277f 2014-11-03 kinaba: /* 143923277f 2014-11-03 kinaba: CASE(6) 143923277f 2014-11-03 kinaba: int size_[] = ; 143923277f 2014-11-03 kinaba: vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 143923277f 2014-11-03 kinaba: int maxSizeSum = ; 143923277f 2014-11-03 kinaba: int _ = ; 143923277f 2014-11-03 kinaba: END 143923277f 2014-11-03 kinaba: CASE(7) 143923277f 2014-11-03 kinaba: int size_[] = ; 143923277f 2014-11-03 kinaba: vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 143923277f 2014-11-03 kinaba: int maxSizeSum = ; 143923277f 2014-11-03 kinaba: int _ = ; 143923277f 2014-11-03 kinaba: END 143923277f 2014-11-03 kinaba: */ 143923277f 2014-11-03 kinaba: } 143923277f 2014-11-03 kinaba: // END CUT HERE