#include <bits/stdc++.h>
#define Alora "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define all(v) v.begin(), v.end()
#define pb push_back
#define maxn 10088
const int M = 1e9 + 7;
using namespace std;
int n, l, r[55];
ll res, C[55][maxn], gt[55], dp[2][55][maxn];
void add(ll &x, ll y){x = (x + y) % M;}
ll mul(ll x, ll y) {return x*y % M;}
void pre(){
fi(i, 1, l + n) C[0][i] = 1;
C[1][1] = 1;
fi(i, 2, l + n){
fi(j, 1, min(50, i)){
add(C[j][i], C[j][i - 1] + C[j - 1][i - 1]);
}
}
gt[0] = 1;
fi(i, 1, n) gt[i] = 1ll*gt[i - 1]*i % M;
}
void sub1(){
if(n == 1) {cout << l; exit(0);}
int len = l - (1 + r[1]*(n - 1));
if(len < 0){cout << 0; exit(0);}
len += n;
cout << C[n][len]*gt[n] % M;
exit(0);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
if(fopen(Alora".inp", "r")){
freopen(Alora".inp", "r", stdin);
freopen(Alora".out", "w", stdout);}
cin >> n >> l;
pre();
fi(i, 1, n) cin >> r[i];
sort(r + 1, r + n + 1);
if(r[1] == r[n]) sub1();
dp[0][0][0] = 1;
fi(i, 0, n - 1){
fi(j, 0, i){
fi(d, 0, l) if(dp[0][j][d]){
ll x = dp[0][j][d];
add(dp[1][j + 1][d + 1], x);
if(d + r[i + 1] <= l) add(dp[1][j][d + r[i + 1]], mul(x, 2*j));
if(j && d + 2*r[i + 1] - 1 <= l) add(dp[1][j - 1][d + 2*r[i + 1] - 1], mul(x, j*(j - 1)));
}
}
swap(dp[0], dp[1]);
fi(j, 0, i) fi(d, 0, l) dp[1][j][d] = 0;
}
fi(d, 1, l) add(res, mul(dp[0][1][d], C[n][l - d + n]));
cout << res;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(Alora".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(Alora".out", "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4552 KB |
Output is correct |
5 |
Correct |
2 ms |
3572 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
3676 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3420 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
13144 KB |
Output is correct |
2 |
Correct |
6 ms |
12124 KB |
Output is correct |
3 |
Correct |
13 ms |
13144 KB |
Output is correct |
4 |
Correct |
7 ms |
12632 KB |
Output is correct |
5 |
Correct |
9 ms |
13144 KB |
Output is correct |
6 |
Correct |
7 ms |
11868 KB |
Output is correct |
7 |
Correct |
10 ms |
13148 KB |
Output is correct |
8 |
Correct |
7 ms |
11100 KB |
Output is correct |
9 |
Correct |
7 ms |
12124 KB |
Output is correct |
10 |
Correct |
1 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
10844 KB |
Output is correct |
2 |
Correct |
11 ms |
10844 KB |
Output is correct |
3 |
Correct |
15 ms |
11072 KB |
Output is correct |
4 |
Correct |
12 ms |
10844 KB |
Output is correct |
5 |
Correct |
15 ms |
11068 KB |
Output is correct |
6 |
Correct |
11 ms |
10844 KB |
Output is correct |
7 |
Correct |
15 ms |
11076 KB |
Output is correct |
8 |
Correct |
8 ms |
10844 KB |
Output is correct |
9 |
Correct |
12 ms |
11060 KB |
Output is correct |
10 |
Correct |
10 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4552 KB |
Output is correct |
5 |
Correct |
2 ms |
3572 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
3676 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3420 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
12 ms |
13144 KB |
Output is correct |
12 |
Correct |
6 ms |
12124 KB |
Output is correct |
13 |
Correct |
13 ms |
13144 KB |
Output is correct |
14 |
Correct |
7 ms |
12632 KB |
Output is correct |
15 |
Correct |
9 ms |
13144 KB |
Output is correct |
16 |
Correct |
7 ms |
11868 KB |
Output is correct |
17 |
Correct |
10 ms |
13148 KB |
Output is correct |
18 |
Correct |
7 ms |
11100 KB |
Output is correct |
19 |
Correct |
7 ms |
12124 KB |
Output is correct |
20 |
Correct |
1 ms |
3420 KB |
Output is correct |
21 |
Correct |
15 ms |
10844 KB |
Output is correct |
22 |
Correct |
11 ms |
10844 KB |
Output is correct |
23 |
Correct |
15 ms |
11072 KB |
Output is correct |
24 |
Correct |
12 ms |
10844 KB |
Output is correct |
25 |
Correct |
15 ms |
11068 KB |
Output is correct |
26 |
Correct |
11 ms |
10844 KB |
Output is correct |
27 |
Correct |
15 ms |
11076 KB |
Output is correct |
28 |
Correct |
8 ms |
10844 KB |
Output is correct |
29 |
Correct |
12 ms |
11060 KB |
Output is correct |
30 |
Correct |
10 ms |
10844 KB |
Output is correct |
31 |
Correct |
43 ms |
13400 KB |
Output is correct |
32 |
Correct |
36 ms |
12628 KB |
Output is correct |
33 |
Correct |
44 ms |
13168 KB |
Output is correct |
34 |
Correct |
18 ms |
12376 KB |
Output is correct |
35 |
Correct |
42 ms |
13144 KB |
Output is correct |
36 |
Correct |
11 ms |
12380 KB |
Output is correct |
37 |
Correct |
43 ms |
13148 KB |
Output is correct |
38 |
Correct |
25 ms |
11356 KB |
Output is correct |
39 |
Correct |
42 ms |
13148 KB |
Output is correct |
40 |
Correct |
19 ms |
12892 KB |
Output is correct |
41 |
Correct |
41 ms |
13148 KB |
Output is correct |
42 |
Correct |
9 ms |
11356 KB |
Output is correct |
43 |
Correct |
34 ms |
13148 KB |
Output is correct |
44 |
Correct |
14 ms |
12380 KB |
Output is correct |
45 |
Correct |
35 ms |
13148 KB |
Output is correct |
46 |
Correct |
6 ms |
12892 KB |
Output is correct |
47 |
Correct |
20 ms |
12636 KB |
Output is correct |
48 |
Correct |
19 ms |
11356 KB |
Output is correct |
49 |
Correct |
8 ms |
12636 KB |
Output is correct |
50 |
Correct |
8 ms |
10844 KB |
Output is correct |