#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 1000000
#define till 1000001
// # of primes till 1e6 = 7e4
using namespace std;
using pii = array<int,2>;
const int mod=1000000007ll;
void mul(int*a,int b){
*a=((*a%mod)*(b%mod));
}
int mul(int a,int b){
return ((a%mod)*(b%mod))%mod;
}
int expo(int a,int b){
int ans=1;
while(b){
if(b&1){
mul(&ans,a);
}
mul(&a,a);
b>>=1;
}
return ans;
}
int fact[20001];
int divy[20001];
int comb(int a,int b){
return mul(mul(fact[a],divy[b]),divy[a-b]);
}
void solve(){
int n,l;
cin>>n>>l;
fact[0]=1;
divy[0]=1;
for(int i=1;i<20001;i++){
fact[i]=mul(fact[i-1],i);
divy[i]=expo(fact[i],mod-2);
}
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
if(a[0]==a[n-1]){
if(a[0]*(n-1)+1>l){
cout<<"0\n";
return;
}
cout<<mul(fact[n],comb(l-a[0]*(n-1)-1+n,n));
}else{
pii b[n];
for(int i=0;i<n;i++){
b[i]={a[i],i};
}
sort(b,b+n);
int ans=0;
do{
int sums=l-1;
for(int i=0;i<n-1;i++){
sums-=max(b[i][0],b[i+1][0]);
}
//cerr<<sums<<"\n";
ans+=comb(sums+n,n);
}while(next_permutation(b,b+n));
cout<<ans<<"\n";
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
44 ms |
11344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
1624 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
1624 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
48 ms |
11856 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
44 ms |
11344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |