#include <bits/stdc++.h>
constexpr int P = 1E9 + 7;
using i64 = long long;
// assume -P <= x < 2P
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(P - x));
}
Z inv() const {
assert(x != 0);
return power(*this, P - 2);
}
Z &operator*=(const Z &rhs) {
x = i64(x) * rhs.x % P;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
};
constexpr int N = 1005;
Z dp[2][105][3][N + 1];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, L;
std::cin >> n >> L;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
std::sort(a.begin(), a.end());
if (n == 1) {
std::cout << 1 << "\n";
return 0;
}
int cur = 0;
dp[cur][0][0][0] = 1;
for (int i = 0; i < n; i++) {
int x = i == 0 ? 0 : a[i] - a[i - 1];
cur ^= 1;
std::memset(dp[cur], 0, sizeof dp[cur]);
for (int c = 0; c < n; c++) {
for (int j = 0; j <= N; j++) {
if (j + 2 * c * x <= N) {
int to = j + 2 * c * x;
dp[cur][c + 1][0][to] += (c + 1) * dp[cur ^ 1][c][0][j];
dp[cur][c + 1][1][to] += 2 * dp[cur ^ 1][c][0][j];
if (c > 0) {
dp[cur][c][1][to] += 2 * dp[cur ^ 1][c][0][j];
dp[cur][c][0][to] += 2 * c * dp[cur ^ 1][c][0][j];
}
if (c > 1) {
dp[cur][c - 1][0][to] += (c - 1) * dp[cur ^ 1][c][0][j];
}
}
if (c > 0 && j + (2 * c - 1) * x <= N) {
int to = j + (2 * c - 1) * x;
dp[cur][c + 1][1][to] += c * dp[cur ^ 1][c][1][j];
dp[cur][c + 1][2][to] += dp[cur ^ 1][c][1][j];
if (c > 0) {
dp[cur][c][2][to] += dp[cur ^ 1][c][1][j];
dp[cur][c][1][to] += (2 * c - 1) * dp[cur ^ 1][c][1][j];
}
if (c > 1) {
dp[cur][c - 1][1][to] += (c - 1) * dp[cur ^ 1][c][1][j];
}
}
if (c > 1 && j + (2 * c - 2) * x <= N) {
int to = j + (2 * c - 2) * x;
dp[cur][c + 1][2][to] += (c - 1) * dp[cur ^ 1][c][2][j];
if (c > 0) {
dp[cur][c][2][to] += (2 * c - 2) * dp[cur ^ 1][c][2][j];
}
if (c > 1) {
dp[cur][c - 1][2][to] += (c - 1) * dp[cur ^ 1][c][2][j];
}
}
}
}
}
std::cout << std::accumulate(dp[cur][1][2], dp[cur][1][2] + L + 1, Z(0)).val() << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2796 KB |
Output is correct |
4 |
Correct |
2 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2796 KB |
Output is correct |
6 |
Correct |
3 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2800 KB |
Output is correct |
8 |
Correct |
4 ms |
2764 KB |
Output is correct |
9 |
Correct |
3 ms |
2764 KB |
Output is correct |
10 |
Correct |
4 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2764 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
3 |
Correct |
7 ms |
2764 KB |
Output is correct |
4 |
Correct |
7 ms |
2796 KB |
Output is correct |
5 |
Correct |
7 ms |
2764 KB |
Output is correct |
6 |
Correct |
7 ms |
2792 KB |
Output is correct |
7 |
Correct |
8 ms |
2796 KB |
Output is correct |
8 |
Correct |
7 ms |
2892 KB |
Output is correct |
9 |
Correct |
8 ms |
2764 KB |
Output is correct |
10 |
Correct |
8 ms |
2776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2796 KB |
Output is correct |
4 |
Correct |
2 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2796 KB |
Output is correct |
6 |
Correct |
3 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2800 KB |
Output is correct |
8 |
Correct |
4 ms |
2764 KB |
Output is correct |
9 |
Correct |
3 ms |
2764 KB |
Output is correct |
10 |
Correct |
4 ms |
2764 KB |
Output is correct |
11 |
Correct |
8 ms |
2764 KB |
Output is correct |
12 |
Correct |
7 ms |
2796 KB |
Output is correct |
13 |
Correct |
7 ms |
2764 KB |
Output is correct |
14 |
Correct |
7 ms |
2796 KB |
Output is correct |
15 |
Correct |
7 ms |
2764 KB |
Output is correct |
16 |
Correct |
7 ms |
2792 KB |
Output is correct |
17 |
Correct |
8 ms |
2796 KB |
Output is correct |
18 |
Correct |
7 ms |
2892 KB |
Output is correct |
19 |
Correct |
8 ms |
2764 KB |
Output is correct |
20 |
Correct |
8 ms |
2776 KB |
Output is correct |
21 |
Correct |
51 ms |
2764 KB |
Output is correct |
22 |
Correct |
167 ms |
2776 KB |
Output is correct |
23 |
Correct |
155 ms |
2764 KB |
Output is correct |
24 |
Correct |
197 ms |
2764 KB |
Output is correct |
25 |
Correct |
146 ms |
2780 KB |
Output is correct |
26 |
Correct |
161 ms |
2884 KB |
Output is correct |
27 |
Correct |
329 ms |
2780 KB |
Output is correct |
28 |
Correct |
293 ms |
2772 KB |
Output is correct |
29 |
Correct |
251 ms |
2784 KB |
Output is correct |
30 |
Correct |
144 ms |
2764 KB |
Output is correct |