#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double dou;
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define MASK(x) (1LL<<(x))
#define BITj(x, j) (((x)>>(j))&1)
template<typename T> bool maximize(T &x, const T &y) {
if (x < y) {x = y; return 1;}
return 0;
}
template<typename T> bool minimize(T &x, const T &y) {
if (x > y) {x = y; return 1;}
return 0;
}
namespace modulofunc{
const int mod = 1e9+7;
void ad(int &x, int y) {
ll temp = x+y;
if (temp >= mod) temp -= mod;
x = temp;
}
int add(int x, int y) {
ll temp = x+y;
if (temp >= mod) temp -= mod;
return temp;
}
int sub(int x, int y) {
ll temp = x-y;
if (temp < 0) temp += mod;
return temp;
}
int mul(int x, int y) {
return 1LL*x*y%mod;
}
}
using namespace modulofunc;
const int maxn = 105, maxl = 1005;
int n, l, a[maxn];
int dp[maxn][maxn][maxl][3];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// #define name "task"
// if (fopen(name".inp", "r")) {
// freopen(name".inp", "r", stdin);
// freopen(name".out", "w", stdout);
// }
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] = l+1;
memset(dp, 0, sizeof(dp));
dp[0][0][0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
for (int r = 0; r <= l; r++) {
for (int k = 0; k < 3; k++) {
if (!dp[i][j][r][k]) continue;
int &ret = dp[i][j][r][k];
int temp = a[i+2]-a[i+1];
//horizontal
//join
if (j > 1 && r+(2*(j-1)-k)*temp <= l) ad(dp[i+1][j-1][r+(2*(j-1)-k)*temp][k], mul(ret, j-1));
//con
if (j > 0 && r+(2*j-k)*temp <= l) ad(dp[i+1][j][r+(2*j-k)*temp][k], mul(ret, 2*j-k));
//new
if (r+(2*(j+1)-k)*temp <= l)ad(dp[i+1][j+1][r+(2*(j+1)-k)*temp][k], mul(ret, j+1-k));
//edge
if (k < 2) {
//con
if (j > 0 && r+(2*j-k-1)*temp <= l) ad(dp[i+1][j][r+(2*j-k-1)*temp][k+1], mul(ret, 2-k));
//new
if (r+(2*(j+1)-k-1)*temp <= l) ad(dp[i+1][j+1][r+(2*(j+1)-k-1)*temp][k+1], mul(ret, 2-k));
}
// cout << i << ' ' << j << ' ' << r << ' ' << r-maxl << ' ' << k << ' ' << ret << "\n";
}
}
}
}
int res = 0;
for (int r = 0; r <= l; r++) {
ad(res, dp[n][1][r][2]);
}
cout << res;
}
/*
3 793
832 436 766
4 10
3 6 2 9
8 35
3 7 1 5 10 2 11 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
54 ms |
130528 KB |
Output is correct |
3 |
Correct |
54 ms |
130368 KB |
Output is correct |
4 |
Correct |
59 ms |
130388 KB |
Output is correct |
5 |
Correct |
55 ms |
130444 KB |
Output is correct |
6 |
Correct |
55 ms |
130388 KB |
Output is correct |
7 |
Correct |
54 ms |
130384 KB |
Output is correct |
8 |
Correct |
57 ms |
130388 KB |
Output is correct |
9 |
Correct |
58 ms |
130384 KB |
Output is correct |
10 |
Correct |
55 ms |
130384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
130312 KB |
Output is correct |
2 |
Correct |
61 ms |
130420 KB |
Output is correct |
3 |
Correct |
60 ms |
130388 KB |
Output is correct |
4 |
Correct |
57 ms |
130388 KB |
Output is correct |
5 |
Correct |
57 ms |
130384 KB |
Output is correct |
6 |
Correct |
60 ms |
130452 KB |
Output is correct |
7 |
Correct |
60 ms |
130400 KB |
Output is correct |
8 |
Correct |
56 ms |
130388 KB |
Output is correct |
9 |
Correct |
56 ms |
130408 KB |
Output is correct |
10 |
Correct |
59 ms |
130452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
54 ms |
130528 KB |
Output is correct |
3 |
Correct |
54 ms |
130368 KB |
Output is correct |
4 |
Correct |
59 ms |
130388 KB |
Output is correct |
5 |
Correct |
55 ms |
130444 KB |
Output is correct |
6 |
Correct |
55 ms |
130388 KB |
Output is correct |
7 |
Correct |
54 ms |
130384 KB |
Output is correct |
8 |
Correct |
57 ms |
130388 KB |
Output is correct |
9 |
Correct |
58 ms |
130384 KB |
Output is correct |
10 |
Correct |
55 ms |
130384 KB |
Output is correct |
11 |
Correct |
63 ms |
130312 KB |
Output is correct |
12 |
Correct |
61 ms |
130420 KB |
Output is correct |
13 |
Correct |
60 ms |
130388 KB |
Output is correct |
14 |
Correct |
57 ms |
130388 KB |
Output is correct |
15 |
Correct |
57 ms |
130384 KB |
Output is correct |
16 |
Correct |
60 ms |
130452 KB |
Output is correct |
17 |
Correct |
60 ms |
130400 KB |
Output is correct |
18 |
Correct |
56 ms |
130388 KB |
Output is correct |
19 |
Correct |
56 ms |
130408 KB |
Output is correct |
20 |
Correct |
59 ms |
130452 KB |
Output is correct |
21 |
Correct |
57 ms |
130388 KB |
Output is correct |
22 |
Correct |
91 ms |
130384 KB |
Output is correct |
23 |
Correct |
72 ms |
130388 KB |
Output is correct |
24 |
Correct |
72 ms |
130304 KB |
Output is correct |
25 |
Correct |
73 ms |
130384 KB |
Output is correct |
26 |
Correct |
71 ms |
130384 KB |
Output is correct |
27 |
Correct |
63 ms |
130384 KB |
Output is correct |
28 |
Correct |
70 ms |
130480 KB |
Output is correct |
29 |
Correct |
73 ms |
130396 KB |
Output is correct |
30 |
Correct |
73 ms |
130448 KB |
Output is correct |