# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
31410 |
2017-08-21T15:10:32 Z |
gs14004 |
카드 (kriii4_Z) |
C++14 |
|
1000 ms |
72976 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<double> base;
void fft(vector<base> &v, bool inv){
int n = v.size();
vector<base> w(n/2), aux(n);
for(int i=0; i<n/2; i++){
int k = i&-i;
if(i == k){
double ang = 2 * M_PI * i / n;
if(inv) ang *= -1;
w[i] = base(cos(ang), sin(ang));
}
else w[i] = w[i-k] * w[k];
}
for(int i=n/2; i; i>>=1){
aux = v;
for(int k=0; 2*k<n; k+=i){
for(int j=0; j<i; j++){
base a = aux[2*k + j], b = aux[2*k + j + i] * w[k];
v[k + j] = a + b;
v[k + j + n/2] = a - b;
}
}
}
if(inv){
for(int i=0; i<n; i++){
v[i] /= n;
}
}
}
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 = 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++){
v1[i] = base(v[i] / b, 0);
v2[i] = base(v[i] % b, 0);
}
for(int i=0; i<w.size(); i++){
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++){
ret[i] = (lint)round(r1[i].real()) * b * b + (lint)round(r2[i].real()) * b + (lint)round(r3[i].real());
}
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];
lint d2[MAXN][MAXN];
void Do(int x, int c){
memset(d2, 0, sizeof(d2));
d2[0][0] = 1;
vector<lint> ret(l + 1), piv(l + 1);
for(int i=1; i<=c; i++){
for(int j=0; j<=l; j++){
for(int k=0; k<=j-x; k++){
d2[i][j] += d2[i-1][k] * bino(j, k) % mod;
}
d2[i][j] %= mod;
}
}
for(int i=0; i<=l; i++) func[i] = d2[c][i];
}
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++){
Do(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 '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:55:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(n < max(v.size(), w.size())) n <<= 1;
^
Z.cpp:58:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<v.size(); i++){
^
Z.cpp:62:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<w.size(); i++){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
72976 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
72976 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |