#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
const int N = 50, M = 1e9+7, L = 1e4;
int n, l;
pair<int, int> r[N];
ll fact[L+52];
ll fp(ll b, ll p) {
ll ret = 1;
while (p) {
if ((p & 1))ret = (ret * b) % M;
b = (b * b) % M;
p >>= 1;
}
return ret;
}
ll nCr(int a, int b) {
if (a < 0 || b > a)return 0;
return (fact[a] * fp((fact[b] * fact[n-b])%M, M-2))%M;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> l;
fact[0] = 1;
for (ll i = 1; i <= L+50; i++) {
fact[i] = (fact[i-1] * i) % M;
}
for (int i = 0; i < n; i++) {
cin >> r[i].F;
r[i].S = i;
}
sort(r, r+n);
if (r[0] == r[n-1]) {
cout << (fact[n] * nCr(l - (n-1)*r[0].F + n - 1, n))%M << "\n";
return 0;
}
if (n <= 10) {
ll ans = 0;
do {
int len = 1;
for (int i = 1; i < n; i++) {
len += max(r[i].F, r[i-1].F);
}
ans = (ans + nCr(l - len + n, n)) % M;
} while(next_permutation(r, r+n));
cout << ans << "\n";
return 0;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
472 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |