Submission #31418

# Submission time Handle Problem Language Result Execution time Memory
31418 2017-08-22T05:24:07 Z gs14004 카드 (kriii4_Z) C++14
13 / 100
1000 ms 2612 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 3005;
const int mod = 1e9 + 7;

namespace fft{
	typedef complex<long double> base;
	void fft(vector<base> &a, bool inv){
		int j = 0;
		for(int i=1; i<a.size(); i++){
			int bit = a.size() >> 1;
			while(j >= bit){
				j -= bit;
				bit >>= 1;
			}
			j += bit;
			if(i < j) swap(a[i], a[j]);
		}
		for(int i=2; i<=a.size(); i<<=1){
			double w = 2 * M_PI / i * (inv ? -1 : 1);
			base x = base(cos(w), sin(w));
			for(int j=0; j<a.size(); j+=i){
				base y = base(1);
				for(int k=0; k<i/2; k++){
					base u = a[j + k], v = a[j + k + i / 2];
					a[j + k] = u + v;
					a[j + k + i/2] = u - v;
					y *= x;
				}
			}
		}
		if(inv){
			for(int i=0; i<a.size(); i++) a[i] /= a.size();
		}
	}
	vector<lint> multiply(vector<lint> &v, vector<lint> &w){
		vector<base> fv(v.begin(), v.end()), fw(w.begin(), w.end());
		int n = 1;
		while(n < max(v.size(), w.size())) n <<= 1;
		n <<= 1;
		fv.resize(n);
		fw.resize(n);
		fft(fv, 0);
		fft(fw, 0);
		for(int i=0; i<n; i++) fv[i] *= fw[i];
		fft(fv, 1);
		vector<lint> ret(n);
		for(int i=0; i<n; i++) ret[i] = round(fv[i].real());
		return ret;
	}
	vector<lint> multiply(vector<lint> &v, vector<lint> &w, int b){
		int n = v.size();
		vector<lint> ret(n);
		for(int i=0; i<n; i++){
			for(int j=0; i+j<n; j++){
				ret[i + j] += v[i] * w[j] % mod;
				ret[i + j] %= mod;
			}
		}
		return ret;
		//int n = 1;
		while(n < max(v.size(), w.size())) n <<= 1;
		n <<= 1;
		vector<base> v1(n), v2(n), v3(n), v4(n), r1(n), r2(n), r3(n);
		for(int i=0; i<v.size(); i++){
			if(v[i] < 0 || v[i] >= mod) puts("err");
			v1[i] = base(v[i] / b, 0);
			v2[i] = base(v[i] % b, 0);
		}
		for(int i=0; i<w.size(); i++){
			if(w[i] < 0 || w[i] >= mod) puts("err");
			v3[i] = base(w[i] / b, 0);
			v4[i] = base(w[i] % b, 0);
		}
		fft(v1, 0);
		fft(v2, 0);
		fft(v3, 0);
		fft(v4, 0);
		for(int i=0; i<n; i++){
			r1[i] = v1[i] * v3[i];
			r2[i] = v1[i] * v4[i] + v2[i] * v3[i];
			r3[i] = v2[i] * v4[i];
		}
		fft(r1, 1);
		fft(r2, 1);
		fft(r3, 1);
		//vector<lint> ret(n);
		for(int i=0; i<n; i++){
			lint av = (lint)round(r1[i].real()) % mod;
			lint bv = (lint)round(r2[i].real()) % mod;
			lint cv = (lint)round(r3[i].real()) % mod;
			av %= mod;
			bv %= mod;
			cv %= mod;
			ret[i] = av * b * b + bv * b + cv;
			ret[i] %= mod;
		}
		return ret;
	}
}

lint ipow(lint x, lint p){
	lint ret = 1, piv = x % mod;
	while(p){
		if(p&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret % mod;
}

lint fact[MAXN], invf[MAXN];

lint bino(int x, int y){
	return fact[x] * (invf[x-y] * invf[y] % mod) % mod;
}

int n, l;
int cnt[MAXN];
lint dp[12][MAXN], func[MAXN];

vector<lint> solve(int x, int c){
	if(c == 0){
		vector<lint> ret(l + 1);
		ret[0] = 1;
		return ret;
	}
	if(c % 2 == 1){
		vector<lint> a = solve(x, c-1);
		vector<lint> b;
		for(int i=0; i<=l; i++){
			a[i] = (a[i] * invf[i]) % mod;
			b.push_back(i < x ? 0 : invf[i]);
		}
		auto ret = fft::multiply(a, b, 1<<15);
		for(int i=0; i<=l; i++){
			ret[i] %= mod;
			ret[i] *= fact[i];
			ret[i] %= mod;
		}
		return ret;
	}
	else{
		auto tmp = solve(x, c / 2);
		for(int i=0; i<=l; i++) tmp[i] = (tmp[i] * invf[i]) % mod;
		auto ret = fft::multiply(tmp, tmp, 1<<15);
		ret.resize(l + 1);
		for(int i=0; i<=l; i++){
			ret[i] %= mod;
			ret[i] *= fact[i];
			ret[i] %= mod;
		}
		return ret;
	}
}

int main(){
	fact[0] = invf[0] = 1;
	for(int i=1; i<MAXN; i++){
		fact[i] = fact[i-1] * i % mod;
		invf[i] = ipow(fact[i], mod - 2);
	}
	cin >> n >> l;
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		cnt[x]++;
	}
	dp[0][0] = 1;
	for(int i=0; i<=10; i++){
		vector<lint> func = solve(i, cnt[i]);
		vector<lint> a, b;
		for(int j=0; j<=l; j++){
			a.push_back(func[j] * invf[j] % mod);
			b.push_back(dp[i][j] * invf[j] % mod);
		}
		auto ret = fft::multiply(a, b, 1<<15);
		for(int j=0; j<=l; j++) dp[i+1][j] = ((ret[j] % mod) * fact[j] % mod);
	}
	dp[11][l] *= ipow(ipow(n, l), mod - 2);
	dp[11][l] %= mod;
	cout << dp[11][l];
}

Compilation message

Z.cpp: In function 'void fft::fft(std::vector<std::complex<long double> >&, bool)':
Z.cpp:12:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1; i<a.size(); i++){
                 ^
Z.cpp:21:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=2; i<=a.size(); i<<=1){
                 ^
Z.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0; j<a.size(); j+=i){
                  ^
Z.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0; i<a.size(); i++) a[i] /= a.size();
                  ^
Z.cpp: In function 'std::vector<long long int> fft::multiply(std::vector<long long int>&, std::vector<long long int>&)':
Z.cpp:41:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(n < max(v.size(), w.size())) n <<= 1;
           ^
Z.cpp: In function 'std::vector<long long int> fft::multiply(std::vector<long long int>&, std::vector<long long int>&, int)':
Z.cpp:64:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(n < max(v.size(), w.size())) n <<= 1;
           ^
Z.cpp:67:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<v.size(); i++){
                 ^
Z.cpp:72:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<w.size(); i++){
                 ^
# Verdict Execution time Memory Grader output
1 Correct 703 ms 2604 KB Output is correct
2 Correct 713 ms 2596 KB Output is correct
3 Correct 513 ms 2608 KB Output is correct
4 Correct 746 ms 2596 KB Output is correct
5 Correct 646 ms 2548 KB Output is correct
6 Correct 576 ms 2608 KB Output is correct
7 Correct 656 ms 2552 KB Output is correct
8 Correct 639 ms 2608 KB Output is correct
9 Correct 676 ms 2604 KB Output is correct
10 Correct 586 ms 2548 KB Output is correct
11 Correct 629 ms 2548 KB Output is correct
12 Correct 563 ms 2548 KB Output is correct
13 Correct 656 ms 2548 KB Output is correct
14 Correct 773 ms 2596 KB Output is correct
15 Correct 636 ms 2548 KB Output is correct
16 Correct 626 ms 2608 KB Output is correct
17 Correct 786 ms 2596 KB Output is correct
18 Correct 646 ms 2608 KB Output is correct
19 Correct 723 ms 2596 KB Output is correct
20 Correct 673 ms 2608 KB Output is correct
21 Correct 606 ms 2608 KB Output is correct
22 Correct 653 ms 2608 KB Output is correct
23 Correct 563 ms 2596 KB Output is correct
24 Correct 613 ms 2596 KB Output is correct
25 Correct 659 ms 2608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 863 ms 2612 KB Output is correct
2 Correct 829 ms 2604 KB Output is correct
3 Execution timed out 1000 ms 2604 KB Execution timed out
4 Halted 0 ms 0 KB -