#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sadd(a, b) a = Add(a, b)
#define smul(a, b) a = Mul(a, b)
using namespace std;
const int N = 100 + 2;
const int M = 1000 + 2;
const int mod = 1e9 + 7;
int Add(int a, int b) {
a += b;
while (a >= mod) a -= mod;
while (a < 0) a += mod;
return a;
}
int Mul(int a, int b) {
ll c = a; c *= b; c %= mod;
return c;
}
int dp[N][M][3], odp[N][M][3], a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, l;
cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> a[i];
if (n == 1) {
cout << 1 << en;
return 0;
}
sort(a + 1, a + n + 1);
if (a[2] - a[1] <= l) dp[1][a[2] - a[1]][1] = 2;
if (2 * (a[2] - a[1]) <= l) dp[1][2 * (a[2] - a[1])][0] = 1;
for (int i = 2; i <= n; i++) {
int diff = a[i + 1] - a[i];
if (i == n) diff = 0;
for (int j = 1; j <= i; j++) {
for (int s = 0; s <= l; s++) {
for (int e = 0; e < 3; e++) {
odp[j][s][e] = dp[j][s][e];
dp[j][s][e] = 0;
}
}
}
for (int j = 1; j <= i; j++) {
for (int s = 0; s <= l; s++) {
for (int e = 0; e < 3; e++) {
int kol = 2 * j - e;
if (s < diff * kol) continue;
sadd(dp[j][s][e], Mul(j - e, odp[j - 1][s - diff * kol][e]));
sadd(dp[j][s][e], Mul(2 * j - e, odp[j][s - diff * kol][e]));
sadd(dp[j][s][e], Mul(j, odp[j + 1][s - diff * kol][e]));
if (e == 0) continue;
sadd(dp[j][s][e], Mul(3 - e, odp[j - 1][s - diff * kol][e - 1]));
sadd(dp[j][s][e], Mul(3 - e, odp[j][s - diff * kol][e - 1]));
}
}
}
}
int ans = 0;
for (int s = 0; s <= l; s++) sadd(ans, dp[1][s][2]);
cout << ans << en;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
340 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 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 |
340 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 |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
154 ms |
2128 KB |
Output is correct |
23 |
Correct |
153 ms |
2660 KB |
Output is correct |
24 |
Correct |
132 ms |
2600 KB |
Output is correct |
25 |
Correct |
141 ms |
2668 KB |
Output is correct |
26 |
Correct |
142 ms |
2640 KB |
Output is correct |
27 |
Correct |
55 ms |
1600 KB |
Output is correct |
28 |
Correct |
59 ms |
1756 KB |
Output is correct |
29 |
Correct |
111 ms |
2428 KB |
Output is correct |
30 |
Correct |
131 ms |
2560 KB |
Output is correct |