#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n;
int lim;
int a[mxN];
int diff[mxN];
int dp[107][107][1007][3];
void add(int &a, int b)
{
a += b;
if(a >= mod)
a -= mod;
}
void solve()
{
cin >> n >> lim;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
for(int i = 1; i <= n; i++) diff[i] = a[i] - a[i - 1];
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
dp[1][1][0][2] = 1;
for(int i = 1; i < n; i++) {
for(int j = 0; j <= i; j++) {
for(int sum = 0; sum <= lim; sum++) {
for(int k = 0; k < 3; k++) {
if(dp[i][j][sum][k] == 0) continue;
int cur = dp[i][j][sum][k];
int newsum = sum + (j * 2 - k) * diff[i + 1];
if(newsum > lim) continue;
// case 1 create comp
add(dp[i + 1][j + 1][newsum][k], 1LL * cur * (j + 1 - k) % mod);
// fill begin or end
if(k < 2) {
add(dp[i + 1][j + 1][newsum][k + 1], 1LL * (2 - k) * cur % mod);
add(dp[i + 1][j][newsum][k + 1], 1LL * (2 - k) * cur % mod);
}
// case 2 merge comp
if(j > 1) {
add(dp[i + 1][j - 1][newsum][k], 1LL * cur * (j - 1) % mod);
}
// case 3 add
add(dp[i + 1][j][newsum][k], 1LL * cur * (j * 2 - k) % mod);
}
}
}
}
int res = 0;
for(int i = 0; i <= lim; i++) add(res, dp[n][1][i][2]);
cout << res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(TASK".inp" , "r" , stdin);
//freopen(TASK".out" , "w" , stdout);
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
276 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
580 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
608 KB |
Output is correct |
9 |
Correct |
1 ms |
712 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
276 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
580 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
608 KB |
Output is correct |
19 |
Correct |
1 ms |
712 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
2 ms |
1236 KB |
Output is correct |
22 |
Correct |
56 ms |
15916 KB |
Output is correct |
23 |
Correct |
44 ms |
6340 KB |
Output is correct |
24 |
Correct |
40 ms |
8988 KB |
Output is correct |
25 |
Correct |
57 ms |
6976 KB |
Output is correct |
26 |
Correct |
40 ms |
6692 KB |
Output is correct |
27 |
Correct |
21 ms |
8268 KB |
Output is correct |
28 |
Correct |
29 ms |
9776 KB |
Output is correct |
29 |
Correct |
47 ms |
12168 KB |
Output is correct |
30 |
Correct |
44 ms |
7116 KB |
Output is correct |