#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];
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];
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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
468 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 |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
324 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |