#include <iostream>
#include <algorithm>
using namespace std;
long long int a[105], f[105][105][1005][3], mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, x;
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n == 1) {
cout << 0;
return 0;
}
sort(a + 1, a + n + 1);
f[1][1][0][0] = 1;
f[1][1][0][1] = 2;
for (int i = 1; i < n; i++) {
for (int j = 0; j <= i; j++) {
for (int k = 0; k <= x; k++) {
for (int l = 0; l <= 2; l++) {
if (f[i][j][k][l] == 0) continue;
long long int h = k + (a[i + 1] - a[i]) * j * 2;
h -= l * (a[i + 1] - a[i]);
if (h > x) continue;
if (j >= 2) f[i + 1][j - 1][h][l] += f[i][j][k][l] * (j - 1) % mod;
if (j >= 1) f[i + 1][j][h][l] += f[i][j][k][l] * (j * 2 - l);
if (l < 2) f[i + 1][j + 1][h][l + 1] += f[i][j][k][l] * (2 - l) % mod;
if (l < 2 && j >= 1) f[i + 1][j][h][l + 1] += f[i][j][k][l] * (2 - l) % mod;
f[i + 1][j + 1][h][l] += f[i][j][k][l] * (j + 1 - l);
}
}
}
}
long long int res = 0;
for (int i = 0; i <= x; i++) {
res += f[n][1][i][2] % mod;
res %= mod;
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
33112 KB |
Output is correct |
3 |
Correct |
4 ms |
33116 KB |
Output is correct |
4 |
Correct |
4 ms |
33292 KB |
Output is correct |
5 |
Correct |
4 ms |
33240 KB |
Output is correct |
6 |
Correct |
4 ms |
33116 KB |
Output is correct |
7 |
Correct |
4 ms |
33116 KB |
Output is correct |
8 |
Correct |
4 ms |
33116 KB |
Output is correct |
9 |
Correct |
4 ms |
33116 KB |
Output is correct |
10 |
Correct |
4 ms |
33236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |