#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1'000'000'007;
const int N = 108, L = 1008;
int dp[N][N][L][3], a[N];
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, l;
cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> a[i];
if (n == 1) {
cout << 1 << '\n';
return 0;
}
sort(a + 1, a + n + 1);
dp[0][0][0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= l; k++) {
for (int m = 0; m <= 2; m++) {
int v = dp[i - 1][j][k][m];
if (!v) continue;
int add = (2 * j - m) * (a[i] - a[i - 1]);
if (k + add > l) continue;
if (j > 1) (dp[i][j - 1][k + add][m] += (v * (j - 1)) % mod) %= mod;
if (j) (dp[i][j][k + add][m] += (v * (2 * j - m)) % mod) %= mod;
(dp[i][j + 1][k + add][m] += (v * (j + 1 - m)) % mod) %= mod;
if (m < 2) {
(dp[i][j + 1][k + add][m + 1] += (v * (2 - m)) % mod) %= mod;
if (j) (dp[i][j][k + add][m + 1] += (v * (2 - m)) % mod) %= mod;
}
}
}
}
}
int ans = 0;
for (int i = 0; i <= l; i++) (ans += dp[n][1][i][2]) %= mod;
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
860 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
860 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
804 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
860 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
860 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
804 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
860 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
40 ms |
25492 KB |
Output is correct |
23 |
Correct |
30 ms |
9556 KB |
Output is correct |
24 |
Correct |
29 ms |
13660 KB |
Output is correct |
25 |
Correct |
30 ms |
10952 KB |
Output is correct |
26 |
Correct |
28 ms |
10072 KB |
Output is correct |
27 |
Correct |
14 ms |
10588 KB |
Output is correct |
28 |
Correct |
18 ms |
12892 KB |
Output is correct |
29 |
Correct |
31 ms |
17744 KB |
Output is correct |
30 |
Correct |
30 ms |
10836 KB |
Output is correct |