Artifact Content
Not logged in

Artifact 43426d2047e44511ab8f9b6a79030300a793518b


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

const int MODVAL = 1000000007;

class NarrowPassage2 { public:
	int count(vector <int> size, int maxSizeSum)
	{
		if(size.size() <= 1)
			return 1;

		int mi = min_element(size.begin(), size.end()) - size.begin();

		int lm=mi;
		for(int k=mi-1; k>=0 && size[k]+size[mi]<=maxSizeSum; --k)
			lm = k;
		int rm=mi;
		for(int k=mi+1; k<size.size() && size[k]+size[mi]<=maxSizeSum; ++k)
			rm = k;

		size.erase(size.begin()+mi);
		return LL(rm-lm+1) * count(size, maxSizeSum) % MODVAL;
	}
};

// 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(_, NarrowPassage2().count(size, maxSizeSum));}
int main(){

CASE(0)
	int size_[] = {1, 2, 3};
	  vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 
	int maxSizeSum = 3; 
	int _ = 2; 
END
CASE(1)
	int size_[] = {1, 2, 3};
	  vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 
	int maxSizeSum = 1000; 
	int _ = 6; 
END
CASE(2)
	int size_[] = {1, 2, 3};
	  vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 
	int maxSizeSum = 4; 
	int _ = 3; 
END
CASE(3)
	int size_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1};
	  vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 
	int maxSizeSum = 2; 
	int _ = 227020758; 
END
CASE(4)
	int size_[] = {2,4,6,1,3,5};
	  vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 
	int maxSizeSum = 8; 
	int _ = 60; 
END
CASE(5)
	int size_[] = {1000000000};
	  vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 
	int maxSizeSum = 1000000000; 
	int _ = 1; 
END
/*
CASE(6)
	int size_[] = ;
	  vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 
	int maxSizeSum = ; 
	int _ = ; 
END
CASE(7)
	int size_[] = ;
	  vector <int> size(size_, size_+sizeof(size_)/sizeof(*size_)); 
	int maxSizeSum = ; 
	int _ = ; 
END
*/
}
// END CUT HERE