#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, L;
ll A[105];
ll D[105][105][1005][3];
const ll MOD = 1e9 + 7;
void add(ll &x, ll y){
y %= MOD;
x += y;
x %= MOD;
}
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N >> L;
for(int i = 1; i <= N; i++){
cin >> A[i];
}
if(N == 1){
cout << 1;
return 0;
}
sort(A + 1, A + N + 1);
A[N + 1] = 1e5;
D[0][0][0][0] = 1;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= i; j++){
for(int k = 0; k <= L; k++){
for(int l = 0; l <= 2; l++){
ll C = (2 * j - l) * (A[i + 1] - A[i]);
if(C > k) continue;
add(D[i][j][k][l], D[i - 1][j - 1][k - C][l]);
add(D[i][j][k][l], (2 * j - l) * D[i - 1][j][k - C][l]);
if(l >= 1) add(D[i][j][k][l], (3 - l) * D[i - 1][j - 1][k - C][l - 1]);
if(l == 1){
add(D[i][j][k][l], 2 * j * D[i - 1][j][k - C][l - 1]);
} else if(l == 2) {
if(i == N){
add(D[i][j][k][l], D[i - 1][j][k - C][l - 1]);
} else if(j >= 2) {
add(D[i][j][k][l], (j - 1) * D[i - 1][j][k - C][l - 1]);
}
}
if(l == 0){
add(D[i][j][k][l], j * (j + 1) * D[i - 1][j + 1][k - C][l]);
} else if(l == 1) {
add(D[i][j][k][l], j * j * D[i - 1][j + 1][k - C][l]);
} else {
if(i == N){
add(D[i][j][k][l], D[i - 1][j + 1][k - C][l]);
} else {
add(D[i][j][k][l], j * (j - 1) * D[i - 1][j + 1][k - C][l]);
}
}
}
}
}
}
ll ans = 0;
for(int i = 0; i <= L; i++){
add(ans, D[N][1][i][2]);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
704 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
704 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
700 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
832 KB |
Output is correct |
7 |
Correct |
1 ms |
704 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
704 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
704 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
700 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
16 |
Correct |
1 ms |
832 KB |
Output is correct |
17 |
Correct |
1 ms |
704 KB |
Output is correct |
18 |
Correct |
1 ms |
716 KB |
Output is correct |
19 |
Correct |
1 ms |
844 KB |
Output is correct |
20 |
Correct |
1 ms |
692 KB |
Output is correct |
21 |
Correct |
3 ms |
3148 KB |
Output is correct |
22 |
Correct |
167 ms |
65500 KB |
Output is correct |
23 |
Correct |
171 ms |
76412 KB |
Output is correct |
24 |
Correct |
154 ms |
74792 KB |
Output is correct |
25 |
Correct |
173 ms |
76948 KB |
Output is correct |
26 |
Correct |
168 ms |
71632 KB |
Output is correct |
27 |
Correct |
64 ms |
41272 KB |
Output is correct |
28 |
Correct |
79 ms |
47812 KB |
Output is correct |
29 |
Correct |
143 ms |
72796 KB |
Output is correct |
30 |
Correct |
173 ms |
77188 KB |
Output is correct |