#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const double pi = acos(-1);
const int N = 1e2 + 5, K = 1e3 + 5, SQ = 500, M = 1e9 + 7;
//#define TESTS
//#define INTERACTIVE
//#define COMMUNICATION
/*
* Remember who you are.
*/
void pre() {
}
void solve() {
int n, L;
cin >> n >> L;
vector<int> a(n);
if (n == 1)
{
cout << 1;
return;
}
for (int i = 0; i < n; ++i)
cin >> a[i];
ranges::sort(a);
vector<vector<vector<vector<int>>>> dp(2, vector<vector<vector<int>>>(n + 1, vector<vector<int>>(L + 1, vector<int>(3))));
for (int i = n; i >= 0; --i)
for (int j = 0; j <= n; ++j)
for (int k = 0; k <= L; ++k)
for (int l = 0; l <= 2; ++l) {
auto &ret = dp[i & 1][j][k][l];
ret = 0;
if (j > i)
continue;
if (i == n) {
ret = j == 1 && l == 2;
continue;
}
int nk = k + (i ? a[i] - a[i - 1] : 0) * (2 * j - l);
if (nk > L || nk < 0)
continue;
if (j + 1 <= n)
ret = 1ll * dp[~i & 1][j + 1][nk][l] * (j + 1 - l) % M;
if (l != 2 && j + 1 <= n)
ret = (ret + 1ll * dp[~i & 1][j + 1][nk][l + 1] * (2 - l) % M) % M;
if (j)
ret = (ret + 1ll * dp[~i & 1][j][nk][l] * (2 * j - l) % M) % M;
if (j && l != 2)
ret = (ret + 1ll * dp[~i & 1][j][nk][l + 1] * (2 - l) % M) % M;
if (j > 1)
ret = (ret + 1ll * dp[~i & 1][j - 1][nk][l] * (j - 1) % M) % M;
}
cout << dp[0][0][0][0];
}
void solve2() {
}
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifdef CAROOT
#ifndef INTERACTIVE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
#else
#endif
int tt = 1;
pre();
#ifdef COMMUNICATION
string run;
cin >> run;
#endif
#ifdef TESTS
cin >> tt;
#endif
for (int tc = 1; tc <= tt; ++tc) {
#ifdef COMMUNICATION
if (run == "first")
solve();
else
solve2();
#else
solve();
#endif
cout << '\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... |