#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 |
1 |
Correct |
5 ms |
596 KB |
Output is correct |
2 |
Correct |
6 ms |
596 KB |
Output is correct |
3 |
Correct |
6 ms |
628 KB |
Output is correct |
4 |
Correct |
7 ms |
624 KB |
Output is correct |
5 |
Correct |
7 ms |
628 KB |
Output is correct |
6 |
Correct |
7 ms |
628 KB |
Output is correct |
7 |
Correct |
5 ms |
596 KB |
Output is correct |
8 |
Correct |
6 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
604 KB |
Output is correct |
2 |
Correct |
6 ms |
596 KB |
Output is correct |
3 |
Correct |
69 ms |
612 KB |
Output is correct |
4 |
Correct |
5 ms |
596 KB |
Output is correct |
5 |
Correct |
66 ms |
612 KB |
Output is correct |
6 |
Correct |
6 ms |
596 KB |
Output is correct |
7 |
Correct |
68 ms |
616 KB |
Output is correct |
8 |
Correct |
49 ms |
612 KB |
Output is correct |
9 |
Correct |
6 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
596 KB |
Output is correct |
2 |
Correct |
6 ms |
596 KB |
Output is correct |
3 |
Correct |
6 ms |
628 KB |
Output is correct |
4 |
Correct |
7 ms |
624 KB |
Output is correct |
5 |
Correct |
7 ms |
628 KB |
Output is correct |
6 |
Correct |
7 ms |
628 KB |
Output is correct |
7 |
Correct |
5 ms |
596 KB |
Output is correct |
8 |
Correct |
6 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
11 |
Correct |
68 ms |
604 KB |
Output is correct |
12 |
Correct |
6 ms |
596 KB |
Output is correct |
13 |
Correct |
69 ms |
612 KB |
Output is correct |
14 |
Correct |
5 ms |
596 KB |
Output is correct |
15 |
Correct |
66 ms |
612 KB |
Output is correct |
16 |
Correct |
6 ms |
596 KB |
Output is correct |
17 |
Correct |
68 ms |
616 KB |
Output is correct |
18 |
Correct |
49 ms |
612 KB |
Output is correct |
19 |
Correct |
6 ms |
596 KB |
Output is correct |
20 |
Correct |
6 ms |
596 KB |
Output is correct |
21 |
Incorrect |
7 ms |
596 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |