#include <bits/stdc++.h>
using namespace std;
#define file ""
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1LL << (x))
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = (int)1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;
template<class X, class Y> bool mini(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int n, L;
int a[N];
long long f[105][105][1005][2][2];
long long calc(int i, int j, int s, int l, int r) {
// int news = s + (j * 2 + l + r) * (a[i] - a[i - 1]);
int news = s;
if (i > 1) news += (j * 2 + l + r) * (a[i] - a[i - 1]);
if (news > L) return 0;
if (j < 0) return 0;
if (i == n) return j == 0;
long long &res = f[i][j][s][l][r];
if (res != -1) return res;
res = 0;
res += calc(i + 1, j, news, 1, r); // append to the left
res += calc(i + 1, j - 1, news, 1, r) * j; // append to the left and merge
res += calc(i + 1, j, news, l, 1); // append to the right
res += calc(i + 1, j - 1, news, l, 1) * j; // append to the right and merge
res += calc(i + 1, j + 1, news, l, r); // new one
res += calc(i + 1, j, news, l, r) * j * 2; // append
res += calc(i + 1, j - 1, news, l, r) * j * (j - 1); // merge
res %= mod;
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin >> n >> L;
for (int i = 1; i <= n; ++i)
cin >> a[i];
sort(a + 1, a + n + 1);
a[0] = a[1];
memset(f, -1, sizeof f);
cout << calc(1, 0, 0, 0, 0);
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
347220 KB |
Output is correct |
2 |
Correct |
37 ms |
347360 KB |
Output is correct |
3 |
Correct |
37 ms |
347220 KB |
Output is correct |
4 |
Correct |
36 ms |
347216 KB |
Output is correct |
5 |
Correct |
37 ms |
347220 KB |
Output is correct |
6 |
Correct |
38 ms |
347220 KB |
Output is correct |
7 |
Correct |
37 ms |
347292 KB |
Output is correct |
8 |
Correct |
37 ms |
347216 KB |
Output is correct |
9 |
Correct |
38 ms |
347168 KB |
Output is correct |
10 |
Correct |
38 ms |
347220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
347228 KB |
Output is correct |
2 |
Correct |
38 ms |
347216 KB |
Output is correct |
3 |
Correct |
37 ms |
347216 KB |
Output is correct |
4 |
Correct |
37 ms |
347388 KB |
Output is correct |
5 |
Correct |
38 ms |
347280 KB |
Output is correct |
6 |
Correct |
37 ms |
347156 KB |
Output is correct |
7 |
Correct |
38 ms |
347368 KB |
Output is correct |
8 |
Correct |
38 ms |
347328 KB |
Output is correct |
9 |
Correct |
38 ms |
347400 KB |
Output is correct |
10 |
Correct |
37 ms |
347216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
347220 KB |
Output is correct |
2 |
Correct |
37 ms |
347360 KB |
Output is correct |
3 |
Correct |
37 ms |
347220 KB |
Output is correct |
4 |
Correct |
36 ms |
347216 KB |
Output is correct |
5 |
Correct |
37 ms |
347220 KB |
Output is correct |
6 |
Correct |
38 ms |
347220 KB |
Output is correct |
7 |
Correct |
37 ms |
347292 KB |
Output is correct |
8 |
Correct |
37 ms |
347216 KB |
Output is correct |
9 |
Correct |
38 ms |
347168 KB |
Output is correct |
10 |
Correct |
38 ms |
347220 KB |
Output is correct |
11 |
Correct |
39 ms |
347228 KB |
Output is correct |
12 |
Correct |
38 ms |
347216 KB |
Output is correct |
13 |
Correct |
37 ms |
347216 KB |
Output is correct |
14 |
Correct |
37 ms |
347388 KB |
Output is correct |
15 |
Correct |
38 ms |
347280 KB |
Output is correct |
16 |
Correct |
37 ms |
347156 KB |
Output is correct |
17 |
Correct |
38 ms |
347368 KB |
Output is correct |
18 |
Correct |
38 ms |
347328 KB |
Output is correct |
19 |
Correct |
38 ms |
347400 KB |
Output is correct |
20 |
Correct |
37 ms |
347216 KB |
Output is correct |
21 |
Correct |
37 ms |
347220 KB |
Output is correct |
22 |
Correct |
159 ms |
347404 KB |
Output is correct |
23 |
Correct |
123 ms |
347408 KB |
Output is correct |
24 |
Correct |
143 ms |
347416 KB |
Output is correct |
25 |
Correct |
127 ms |
347216 KB |
Output is correct |
26 |
Correct |
113 ms |
347412 KB |
Output is correct |
27 |
Correct |
65 ms |
347216 KB |
Output is correct |
28 |
Correct |
76 ms |
347728 KB |
Output is correct |
29 |
Correct |
115 ms |
347416 KB |
Output is correct |
30 |
Correct |
128 ms |
347408 KB |
Output is correct |