092758c493 2015-01-16 kinaba: #include <iostream> 092758c493 2015-01-16 kinaba: #include <sstream> 092758c493 2015-01-16 kinaba: #include <iomanip> 092758c493 2015-01-16 kinaba: #include <vector> 092758c493 2015-01-16 kinaba: #include <string> 092758c493 2015-01-16 kinaba: #include <map> 092758c493 2015-01-16 kinaba: #include <set> 092758c493 2015-01-16 kinaba: #include <algorithm> 092758c493 2015-01-16 kinaba: #include <numeric> 092758c493 2015-01-16 kinaba: #include <iterator> 092758c493 2015-01-16 kinaba: #include <functional> 092758c493 2015-01-16 kinaba: #include <complex> 092758c493 2015-01-16 kinaba: #include <queue> 092758c493 2015-01-16 kinaba: #include <stack> 092758c493 2015-01-16 kinaba: #include <cmath> 092758c493 2015-01-16 kinaba: #include <cassert> 092758c493 2015-01-16 kinaba: #include <tuple> 092758c493 2015-01-16 kinaba: using namespace std; 092758c493 2015-01-16 kinaba: typedef long long LL; 092758c493 2015-01-16 kinaba: typedef complex<double> CMP; 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: static const unsigned MODVAL = 1000000007; 092758c493 2015-01-16 kinaba: struct mint 092758c493 2015-01-16 kinaba: { 092758c493 2015-01-16 kinaba: unsigned val; 092758c493 2015-01-16 kinaba: mint():val(0){} 092758c493 2015-01-16 kinaba: mint(int x):val(x%MODVAL) {} 092758c493 2015-01-16 kinaba: mint(unsigned x):val(x%MODVAL) {} 092758c493 2015-01-16 kinaba: mint(LL x):val(x%MODVAL) {} 092758c493 2015-01-16 kinaba: }; 092758c493 2015-01-16 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 092758c493 2015-01-16 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } 092758c493 2015-01-16 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 092758c493 2015-01-16 kinaba: mint operator+(mint x, mint y) { return x+=y; } 092758c493 2015-01-16 kinaba: mint operator-(mint x, mint y) { return x-=y; } 092758c493 2015-01-16 kinaba: mint operator*(mint x, mint y) { return x*=y; } 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } 092758c493 2015-01-16 kinaba: mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } 092758c493 2015-01-16 kinaba: mint operator/(mint x, mint y) { return x/=y; } 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: vector<mint> FAC_(1,1); 092758c493 2015-01-16 kinaba: mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*(LL)FAC_.size() ); return FAC_[n]; } 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: mint C(LL n, LL k) { return k<0 || n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); } 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: class OkonomiyakiParty { public: 092758c493 2015-01-16 kinaba: int count(vector <int> osize, int M, int K) 092758c493 2015-01-16 kinaba: { 092758c493 2015-01-16 kinaba: mint ans = 0; 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: sort(osize.begin(), osize.end()); 092758c493 2015-01-16 kinaba: for(int s=0; s<osize.size(); ++s) 092758c493 2015-01-16 kinaba: for(int e=s; e<osize.size(); ++e) 092758c493 2015-01-16 kinaba: if( osize[e]-osize[s]<=K ) 092758c493 2015-01-16 kinaba: ans += C(e-s-1, M-2); 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: return ans.val; 092758c493 2015-01-16 kinaba: } 092758c493 2015-01-16 kinaba: }; 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: // BEGIN CUT HERE 092758c493 2015-01-16 kinaba: #include <ctime> 092758c493 2015-01-16 kinaba: double start_time; string timer() 092758c493 2015-01-16 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 092758c493 2015-01-16 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 092758c493 2015-01-16 kinaba: { os << "{ "; 092758c493 2015-01-16 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 092758c493 2015-01-16 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 092758c493 2015-01-16 kinaba: void verify_case(const int& Expected, const int& Received) { 092758c493 2015-01-16 kinaba: bool ok = (Expected == Received); 092758c493 2015-01-16 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 092758c493 2015-01-16 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 092758c493 2015-01-16 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 092758c493 2015-01-16 kinaba: #define END verify_case(_, OkonomiyakiParty().count(osize, M, K));} 092758c493 2015-01-16 kinaba: int main(){ 092758c493 2015-01-16 kinaba: 092758c493 2015-01-16 kinaba: CASE(0) 092758c493 2015-01-16 kinaba: int osize_[] = {1,4,6,7,9}; 092758c493 2015-01-16 kinaba: vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 092758c493 2015-01-16 kinaba: int M = 2; 092758c493 2015-01-16 kinaba: int K = 3; 092758c493 2015-01-16 kinaba: int _ = 6; 092758c493 2015-01-16 kinaba: END 092758c493 2015-01-16 kinaba: CASE(1) 092758c493 2015-01-16 kinaba: int osize_[] = {1,6,2,7,4,2,6,1,5,2,4}; 092758c493 2015-01-16 kinaba: vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 092758c493 2015-01-16 kinaba: int M = 4; 092758c493 2015-01-16 kinaba: int K = 3; 092758c493 2015-01-16 kinaba: int _ = 60; 092758c493 2015-01-16 kinaba: END 092758c493 2015-01-16 kinaba: CASE(2) 092758c493 2015-01-16 kinaba: int osize_[] = {1,4,5,7,10,11,13,16,18}; 092758c493 2015-01-16 kinaba: vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 092758c493 2015-01-16 kinaba: int M = 4; 092758c493 2015-01-16 kinaba: int K = 5; 092758c493 2015-01-16 kinaba: int _ = 0; 092758c493 2015-01-16 kinaba: END 092758c493 2015-01-16 kinaba: CASE(3) 092758c493 2015-01-16 kinaba: int osize_[] = {55,2,7,232,52,5,5332,623,52,6,532,5147}; 092758c493 2015-01-16 kinaba: vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 092758c493 2015-01-16 kinaba: int M = 6; 092758c493 2015-01-16 kinaba: int K = 10000; 092758c493 2015-01-16 kinaba: int _ = 924; 092758c493 2015-01-16 kinaba: END 092758c493 2015-01-16 kinaba: CASE(4) 092758c493 2015-01-16 kinaba: int osize_[] = {5781,8708,1754,4750,9888,3675,4810,1020,922,9834,5695,1101,1236,2496,8431,6727, 092758c493 2015-01-16 kinaba: 1376,3373,4423,1839,7438,9407,1851,6966,8715,2905,542,535,8980,2602,2603,3117,3452, 092758c493 2015-01-16 kinaba: 5682,7775,4356,5140,8923,9801,3729}; 092758c493 2015-01-16 kinaba: vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 092758c493 2015-01-16 kinaba: int M = 15; 092758c493 2015-01-16 kinaba: int K = 4003; 092758c493 2015-01-16 kinaba: int _ = 114514; 092758c493 2015-01-16 kinaba: END 092758c493 2015-01-16 kinaba: /* 092758c493 2015-01-16 kinaba: CASE(5) 092758c493 2015-01-16 kinaba: int osize_[] = ; 092758c493 2015-01-16 kinaba: vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 092758c493 2015-01-16 kinaba: int M = ; 092758c493 2015-01-16 kinaba: int K = ; 092758c493 2015-01-16 kinaba: int _ = ; 092758c493 2015-01-16 kinaba: END 092758c493 2015-01-16 kinaba: CASE(6) 092758c493 2015-01-16 kinaba: int osize_[] = ; 092758c493 2015-01-16 kinaba: vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 092758c493 2015-01-16 kinaba: int M = ; 092758c493 2015-01-16 kinaba: int K = ; 092758c493 2015-01-16 kinaba: int _ = ; 092758c493 2015-01-16 kinaba: END 092758c493 2015-01-16 kinaba: */ 092758c493 2015-01-16 kinaba: } 092758c493 2015-01-16 kinaba: // END CUT HERE