This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll power(ll a,ll b){
if(b==0) return 1;
if(b&1) return power(a,b-1)*a%mod;
ll tmp=power(a,b/2);
return tmp*tmp%mod;
}
ll inverse(ll a){
return power(a,mod-2);
}
int main(){
ll n,l;
cin>>n>>l;
vector<pair<ll,ll>> vec(n);
vector<ll> fac(20001);
fac[0]=1;
for(ll i=1;i<=20000;i++) fac[i]=fac[i-1]*i%mod;
vector<ll> invfac(20001);
for(ll i=0;i<=20000;i++) invfac[i]=inverse(fac[i]);
for(int i=0;i<n;i++) cin>>vec[i].first;
bool flag=1;
for(int i=0;i<n-1;i++){
if(vec[i].first!=vec[i+1].first){
flag=0;
break;
}
}
if(flag){
ll r=vec[0].first;
ll k=(l-1-(n-1)*r);
if(k<0){
cout<<0;
return 0;
}
cout<<fac[k+n]*inverse(fac[n])%mod*inverse(fac[k])%mod*fac[n]%mod;
return 0;
}
if(n<=10){
ll ans=0;
for(int i=0;i<n;i++) vec[i].second=i;
sort(vec.begin(),vec.end());
do{
ll k=l-1;
for(int i=0;i<n-1;i++) k-=max(vec[i].first,vec[i+1].first);
if(k<0) continue;
ans=(ans+fac[k+n]*invfac[n]%mod*invfac[k]%mod)%mod;
}while(next_permutation(vec.begin(),vec.end()));
cout<<ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |