#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]=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();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
118 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1032 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |