Artifact Content
Not logged in

Artifact 938cf19239478ddae4c0f094aff0540478a818f0


#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;

static const unsigned MODVAL = 1000000007;
struct mint
{
	unsigned val;
	mint():val(0){}
	mint(int      x):val(x%MODVAL) {}
	mint(unsigned x):val(x%MODVAL) {}
	mint(LL       x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }

mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }
mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); }
mint operator/(mint x, mint y) { return x/=y; }

vector<mint> FAC_(1,1);
mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*(LL)FAC_.size() ); return FAC_[n]; }

mint C(LL n, LL k) { return k<0 || n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }

class OkonomiyakiParty { public:
	int count(vector <int> osize, int M, int K)
	{
		mint ans = 0;

		sort(osize.begin(), osize.end());
		for(int s=0; s<osize.size(); ++s)
		for(int e=s; e<osize.size(); ++e)
			if( osize[e]-osize[s]<=K )
				ans += C(e-s-1, M-2);

		return ans.val;
	}
};

// 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(_, OkonomiyakiParty().count(osize, M, K));}
int main(){

CASE(0)
	int osize_[] = {1,4,6,7,9};
	  vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 
	int M = 2; 
	int K = 3; 
	int _ = 6; 
END
CASE(1)
	int osize_[] = {1,6,2,7,4,2,6,1,5,2,4};
	  vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 
	int M = 4; 
	int K = 3; 
	int _ = 60; 
END
CASE(2)
	int osize_[] = {1,4,5,7,10,11,13,16,18};
	  vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 
	int M = 4; 
	int K = 5; 
	int _ = 0; 
END
CASE(3)
	int osize_[] = {55,2,7,232,52,5,5332,623,52,6,532,5147};
	  vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 
	int M = 6; 
	int K = 10000; 
	int _ = 924; 
END
CASE(4)
	int osize_[] = {5781,8708,1754,4750,9888,3675,4810,1020,922,9834,5695,1101,1236,2496,8431,6727,
1376,3373,4423,1839,7438,9407,1851,6966,8715,2905,542,535,8980,2602,2603,3117,3452,
5682,7775,4356,5140,8923,9801,3729};
	  vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 
	int M = 15; 
	int K = 4003; 
	int _ = 114514; 
END
/*
CASE(5)
	int osize_[] = ;
	  vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 
	int M = ; 
	int K = ; 
	int _ = ; 
END
CASE(6)
	int osize_[] = ;
	  vector <int> osize(osize_, osize_+sizeof(osize_)/sizeof(*osize_)); 
	int M = ; 
	int K = ; 
	int _ = ; 
END
*/
}
// END CUT HERE