#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
using namespace std;
int fact[20005];
int mult(int x, int y){
return ((x%MOD)*(y%MOD))%MOD;
}
int add(int x, int y){
return (x+y)%MOD;
}
int sub(int x, int y){
if((x-y)<0) return x-y+MOD;
return x-y;
}
int fst(int base, int p){
int res=1;
while(p>0){
if(p%2){
res = mult(res, base);
p--;
}
else{
base = mult(base, base);
p/=2;
}
}
return res;
}
int divi(int x, int y){
y = fst(y, MOD-2);
return mult(x, y);
}
void solve(){
fact[0]=1;
for(int i=1; i<=20003; i++) fact[i] = mult(fact[i-1], i);
int n,l; cin >> n >> l;
if(n<=10 && 0){
int r[n+1];
for(int i=1; i<=n; i++) cin >> r[i];
int arr[n];
for(int i=1; i<=n; i++) arr[i-1]=i;
int ans=0;
do{
int cur=1;
for(int i=0; i<n-1; i++){
int ptr=arr[i], ptr2=arr[i+1];
cur += max(r[ptr], r[ptr2]);
}
//cerr << cur << endl;
if(cur>l) continue;
int k = l-cur;
ans = add(ans, divi(fact[add(n, k)], mult(fact[k], fact[n])));
} while(next_permutation(arr, arr+n));
cout << ans << endl;
}
else{
int r;
for(int i=1; i<=n; i++) cin >> r;
if(mult((n-1), r)+1 > l){
cout << 0 << endl;
return;
}
int k = sub(l, mult((n-1), r)+1);
int ans = divi(fact[add(n, k)], fact[k]);
cout << ans << endl;
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
ll t=1;
//cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |