#include <bits/stdc++.h>
using namespace std;
inline namespace
{
} // namespace
const long MOD = 1'000'000'007;
void solve()
{
int n;
int l;
cin >> n >> l;
vector<int> a(n);
for (int &x : a)
cin >> x;
sort(a.begin(), a.end());
vector dp(3, vector(l + 1, vector<long>(3, 0)));
dp[0][0][0] = 1;
for (int i = 0; i < n - 1; i++)
{
vector nxt_dp(i + 4, vector(l + 1, vector<long>(3, 0)));
for (int j = 1; j <= i + 1; j++)
{
for (int x = 0; x <= l; x++)
{
for (int k = 0; k <= 2; k++)
{
long cost = (2 * j - k) * (a[i + 1] - a[i]);
if (x >= cost)
{
// create new component w/o endpoint
nxt_dp[j][x][k] += (j - k) * dp[j - 1][x - cost][k];
// create new component w/ endpoint
if (k >= 1)
nxt_dp[j][x][k] += (3 - k) * dp[j - 1][x - cost][k - 1];
// add to component w/o endpoint
nxt_dp[j][x][k] += (2 * j - k) * dp[j][x - cost][k];
// add to component w/ endpoint
if (k >= 1)
nxt_dp[j][x][k] += (3 - k) * dp[j][x - cost][k - 1];
// merge two components
nxt_dp[j][x][k] += j * dp[j + 1][x - cost][k];
nxt_dp[j][x][k] %= MOD;
}
}
}
}
dp = move(nxt_dp);
}
long cnt = 0;
if (n == 1)
cnt = 1;
else
{
for (int x = 0; x <= l; x++)
cnt += dp[1][x][1] + dp[2][x][2];
cnt %= MOD;
}
cout << cnt << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
1236 KB |
Output is correct |
6 |
Correct |
3 ms |
1220 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
1236 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
412 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
1236 KB |
Output is correct |
6 |
Correct |
3 ms |
1220 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
1236 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
412 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
176 ms |
7532 KB |
Output is correct |
23 |
Correct |
306 ms |
11228 KB |
Output is correct |
24 |
Correct |
241 ms |
8644 KB |
Output is correct |
25 |
Correct |
304 ms |
11336 KB |
Output is correct |
26 |
Correct |
263 ms |
9712 KB |
Output is correct |
27 |
Correct |
93 ms |
2956 KB |
Output is correct |
28 |
Correct |
101 ms |
3592 KB |
Output is correct |
29 |
Correct |
197 ms |
6672 KB |
Output is correct |
30 |
Correct |
321 ms |
11468 KB |
Output is correct |