#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int MOD = (int) 1e9 + 7;
inline void mod(int &x) {
if(x >= MOD) x -= MOD;
}
inline void add(int &x, int y) {
x += y;
mod(x);
}
const int MAXN = 105;
const int MAXL = 1005;
int dp[MAXN + 1][MAXN + 1][MAXL + 1][2][2];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, j, n, L;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> L;
vector <int> arr(n + 1);
for(i = 1; i <= n; i++) {
cin >> arr[i];
}
sort(arr.begin(), arr.end());
dp[0][0][0][0][0] = 1;
for(i = 0; i < n; i++) {
for(j = 0; j <= i; j++) {
for(int cst = 0; cst <= L; cst++) {
for(int l = 0; l < 2; l++) {
for(int r = 0; r < 2; r++) {
int cur = dp[i][j][cst][l][r];
if(cur == 0) {
continue;
}
int new_cst = cst + (2 * j - l - r) * (arr[i + 1] - arr[i]);
if(new_cst > L) {
continue;
}
add(dp[i + 1][j + 1][new_cst][l][r], cur);
if(l == 0) {
add(dp[i + 1][j + 1][new_cst][1][r], cur);
}
if(r == 0) {
add(dp[i + 1][j + 1][new_cst][l][1], cur);
}
add(dp[i + 1][j][new_cst][l][r], (1LL * cur * (2 * j - l - r)) % MOD);
if(i == n - 1) {
if(l == 0) {
add(dp[i + 1][j][new_cst][1][r], (1LL * cur * j) % MOD);
}
if(r == 0) {
add(dp[i + 1][j][new_cst][l][1], (1LL * cur * j) % MOD);
}
}
else {
if(l == 0) {
add(dp[i + 1][j][new_cst][1][r], (1LL * cur * (j - r)) % MOD);
}
if(r == 0) {
add(dp[i + 1][j][new_cst][l][1], (1LL * cur * (j - l)) % MOD);
}
}
if(j > 0) {
if(i == n - 1) {
int coef = max(0, l * (j - l - r)) + max(0, (j - l - r) * r) + max(0, (j - l - r) * (j - l - r - 1)) + l * r;
add(dp[i + 1][j - 1][new_cst][l][r], (1LL * cur * coef) % MOD);
}
else {
int coef = max(0, l * (j - l - r)) + max(0, (j - l - r) * r) + max(0, (j - l - r) * (j - l - r - 1));
add(dp[i + 1][j - 1][new_cst][l][r], (1LL * cur * coef) % MOD);
}
}
}
}
}
}
}
int ans = 0;
for(i = 0; i <= L; i++) {
add(ans, dp[n][1][i][1][1]);
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |