#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 << 1;
return 0;
}
sort(a + 1, a + n + 1);
f[1][1][0][0] = 1;
f[1][1][0][1] = 2;
for (long long int i = 1; i < n; i++) {
for (long long int j = 0; j <= i; j++) {
for (long long int k = 0; k <= x; k++) {
for (long long int l = 0; l <= 2; l++) {
f[i][j][k][l] %= mod;
if (f[i][j][k][l] == 0) continue;
long long int h = k + (a[i + 1] - a[i]) * (j * 2 - l);
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) % mod;
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) % mod;
}
}
}
}
long long int res = 0;
for (int i = 0; i <= x; i++) {
res += f[n][1][i][2] % mod;
res %= mod;
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
18776 KB |
Output is correct |
6 |
Correct |
3 ms |
18780 KB |
Output is correct |
7 |
Correct |
3 ms |
16728 KB |
Output is correct |
8 |
Correct |
3 ms |
18776 KB |
Output is correct |
9 |
Correct |
3 ms |
18780 KB |
Output is correct |
10 |
Correct |
2 ms |
18780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
29020 KB |
Output is correct |
2 |
Correct |
4 ms |
33116 KB |
Output is correct |
3 |
Correct |
4 ms |
33116 KB |
Output is correct |
4 |
Correct |
4 ms |
33116 KB |
Output is correct |
5 |
Correct |
4 ms |
33116 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 |
33116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
18776 KB |
Output is correct |
6 |
Correct |
3 ms |
18780 KB |
Output is correct |
7 |
Correct |
3 ms |
16728 KB |
Output is correct |
8 |
Correct |
3 ms |
18776 KB |
Output is correct |
9 |
Correct |
3 ms |
18780 KB |
Output is correct |
10 |
Correct |
2 ms |
18780 KB |
Output is correct |
11 |
Correct |
3 ms |
29020 KB |
Output is correct |
12 |
Correct |
4 ms |
33116 KB |
Output is correct |
13 |
Correct |
4 ms |
33116 KB |
Output is correct |
14 |
Correct |
4 ms |
33116 KB |
Output is correct |
15 |
Correct |
4 ms |
33116 KB |
Output is correct |
16 |
Correct |
4 ms |
33116 KB |
Output is correct |
17 |
Correct |
4 ms |
33116 KB |
Output is correct |
18 |
Correct |
4 ms |
33116 KB |
Output is correct |
19 |
Correct |
4 ms |
33116 KB |
Output is correct |
20 |
Correct |
4 ms |
33116 KB |
Output is correct |
21 |
Correct |
9 ms |
88924 KB |
Output is correct |
22 |
Correct |
95 ms |
177320 KB |
Output is correct |
23 |
Correct |
116 ms |
220028 KB |
Output is correct |
24 |
Correct |
107 ms |
216800 KB |
Output is correct |
25 |
Correct |
119 ms |
219984 KB |
Output is correct |
26 |
Correct |
110 ms |
219076 KB |
Output is correct |
27 |
Correct |
50 ms |
179976 KB |
Output is correct |
28 |
Correct |
60 ms |
182812 KB |
Output is correct |
29 |
Correct |
93 ms |
202680 KB |
Output is correct |
30 |
Correct |
120 ms |
220748 KB |
Output is correct |