This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
int main() {
int N, L;
cin >> N >> L;
vector<int> A(N + 1);
for (int i = 1; i <= N; i++)
cin >> A[i];
sort(A.begin() + 1, A.end());
A.push_back(INF);
if (N == 1) {
cout << 1 << '\n';
return 0;
}
vector<vector<vector<array<long long, 3>>>> dp(N + 1, vector<vector<array<long long, 3>>>(N + 1, vector<array<long long, 3>>(L + 1)));
dp[0][0][0][0] = 1;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= i; j++)
for (int k = 0; k <= L; k++)
for (int m = 0; m <= 2; m++)
if (((2 * j - m) * (A[i + 1] - A[i])) <= k && i + j + 1 - m <= N)
dp[i][j][k][m] = ((dp[i - 1][j - 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m]) +(m == 0 ? 0 : (3 - m) * dp[i - 1][j - 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m - 1]) + ((2 * j - m) * dp[i - 1][j][k - ((2 * j - m) * (A[i + 1] - A[i]))][m]) + (m == 0 ? 0 : (m == 1 ? 2 * j * dp[i - 1][j][k - ((2 * j - m) * (A[i + 1] - A[i]))][m - 1] : (i == N ? dp[i - 1][j][k - ((2 * j - m) * (A[i + 1] - A[i]))][m - 1] : (j - 1) * dp[i - 1][j][k - ((2 * j - m) * (A[i + 1] - A[i]))][m - 1]))) + (m == 0 ? j * (j + 1) * dp[i - 1][j + 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m] : (m == 1 ? j * j * dp[i - 1][j + 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m] : (i == N ? dp[i - 1][j + 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m] : j * (j - 1) * dp[i - 1][j + 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m])))) % MOD;
long long ans = 0;
for (int k = 0; k <= L; k++)
ans += dp[N][1][k][2];
cout << ans % MOD << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |