#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void add(int &x, int y) {
x += y;
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
}
int mul(int x, int y) {
return (x * 1LL * y) % MOD;
}
const int N = 100 + 3, M = 1000 + 3;
int n, m, a[N];
int f[N][N][M][3];
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
sort(a + 1, a + n + 1);
a[n + 1] = a[n];
if (n == 1) {
cout << 1;
return;
}
f[0][0][0][0] = 1;
for (int i = 0; i < n; ++i) {
int x = a[i + 2] - a[i + 1];
for (int j = 0; j <= i; ++j) {
for (int k = 0; k <= m; ++k) {
for (int l = 0; l < 3; ++l) if (f[i][j][k][l]) {
if (k + (2 * j - l + 2) * x <= m)
add(f[i + 1][j + 1][k + (2 * j - l + 2) * x][l], mul(f[i][j][k][l], j - l + 1));
if (l < 2 && k + (2 * j - l + 1) * x <= m)
add(f[i + 1][j + 1][k + (2 * j - l + 1) * x][l + 1], mul(f[i][j][k][l], 2 - l));
if (k + (2 * j - l) * x <= m)
add(f[i + 1][j][k + (2 * j - l) * x][l], mul(f[i][j][k][l], 2 * j - l));
if (l < 2 && k + (2 * j - l - 1) * x <= m)
add(f[i + 1][j][k + (2 * j - l - 1) * x][l + 1], mul(f[i][j][k][l], 2 - l));
if (j - 1 > 0 && k + (2 * j - l - 2) * x <= m)
add(f[i + 1][j - 1][k + (2 * j - l - 2) * x][l], mul(f[i][j][k][l], j - 1));
}
}
}
}
int ans = 0;
for (int i = 0; i <= m; ++i)
add(ans, f[n][1][i][2]);
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
1080 KB |
Output is correct |
22 |
Correct |
92 ms |
15212 KB |
Output is correct |
23 |
Correct |
43 ms |
5320 KB |
Output is correct |
24 |
Correct |
50 ms |
8144 KB |
Output is correct |
25 |
Correct |
46 ms |
6108 KB |
Output is correct |
26 |
Correct |
40 ms |
5832 KB |
Output is correct |
27 |
Correct |
28 ms |
7960 KB |
Output is correct |
28 |
Correct |
35 ms |
9320 KB |
Output is correct |
29 |
Correct |
60 ms |
11356 KB |
Output is correct |
30 |
Correct |
44 ms |
6172 KB |
Output is correct |