#include <bits/stdc++.h>
using namespace std;
#define int long long
const int P = (int)1e9 + 7;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, l;
cin >> n >> l;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
// (comp, cnt, sum): 'comp' components, 'cnt' bounding elements, total delta of 'sum' | after adding a[i]
vector<vector<vector<int>>> prev(n + 1, vector<vector<int>>(3, vector<int>(l + 1, 0)));
prev[1][0][0] = 1;
prev[1][1][0] = 2;
for (int i = 1; i < n; i++) {
vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(3, vector<int>(l + 1, 0)));
int d = a[i] - a[i - 1];
for (int comp = 0; comp <= n; comp++) {
for (int sum = 0; sum <= l; sum++) {
// 0 bounding element
if (sum + (2 * comp) * d <= l) {
if (comp + 1 <= n) (dp[comp + 1][0][sum + (2 * comp) * d] += (comp + 1) * prev[comp][0][sum]) %= P;
(dp[comp][0][sum + (2 * comp) * d] += (2 * comp) * prev[comp][0][sum]) %= P;
if (comp - 1 >= 0) (dp[comp - 1][0][sum + (2 * comp) * d] += (comp - 1) * prev[comp][0][sum]) %= P;
}
// 1 bounding element
if (0 <= sum + (2 * comp - 1) * d && sum + (2 * comp - 1) * d <= l) {
if (comp + 1 <= n) (dp[comp + 1][1][sum + (2 * comp - 1) * d] += (comp) * prev[comp][1][sum]) %= P;
(dp[comp][1][sum + (2 * comp - 1) * d] += (2 * comp - 1) * prev[comp][1][sum]) %= P;
if (comp - 1 >= 0) (dp[comp - 1][1][sum + (2 * comp - 1) * d] += (comp - 1) * prev[comp][1][sum]) %= P;
}
if (sum + (2 * comp) * d <= l) {
if (comp + 1 <= n) (dp[comp + 1][1][sum + (2 * comp) * d] += 2 * prev[comp][0][sum]) %= P;
(dp[comp][1][sum + (2 * comp) * d] += 2 * prev[comp][0][sum]) %= P;
}
// 2 bounding elements
if (0 <= sum + (2 * comp - 2) * d && sum + (2 * comp - 2) * d <= l) {
if (comp + 1 <= n) (dp[comp + 1][2][sum + (2 * comp - 2) * d] += (comp - 1) * prev[comp][2][sum]) %= P;
(dp[comp][2][sum + (2 * comp - 2) * d] += (2 * comp - 2) * prev[comp][2][sum]) %= P;
if (comp - 1 >= 0) (dp[comp - 1][2][sum + (2 * comp - 2) * d] += (comp - 1) * prev[comp][2][sum]) %= P;
}
if (0 <= sum + (2 * comp - 1) * d && sum + (2 * comp - 1) * d <= l) {
if (comp + 1 <= n) (dp[comp + 1][2][sum + (2 * comp - 1) * d] += prev[comp][1][sum]) %= P;
(dp[comp][2][sum + (2 * comp - 1) * d] += prev[comp][1][sum]) %= P;
}
}
}
swap(dp, prev);
}
cout << accumulate(prev[1][2].begin(), prev[1][2].end(), 0LL) % P << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
448 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |