#include <bits/stdc++.h>
using namespace std;
const int N = 101, L = 1001, M = 1000000007;
struct mint {
int x;
mint() : x(0) {}
template <class T> mint(T value) : x(value % M) { if (x < 0) x += M; }
mint & operator+=(const mint &oth) { x += oth.x; if (x >= M) x -= M; return *this; }
mint & operator-=(const mint &oth) { x -= oth.x; if (x < 0) x += M; return *this; }
mint & operator*=(const mint &oth) { x = (long long) x * oth.x % M; return *this; }
friend mint operator+(mint l, const mint &r) { return l += r; }
friend mint operator-(mint l, const mint &r) { return l -= r; }
friend mint operator*(mint l, const mint &r) { return l *= r; }
mint & operator--() { if (--x == -1) x = M - 1; return *this; }
mint & operator++() { if (++x == M) x = 0; return *this; }
mint operator--(int) { mint temp = *this; --*this; return temp; }
mint operator++(int) { mint temp = *this; ++*this; return temp; }
mint operator-() const { return 0 - *this; }
mint operator+() const { return *this; }
friend bool operator==(const mint &l, const mint &r) { return l.x == r.x; }
friend bool operator!=(const mint &l, const mint &r) { return l.x != r.x; }
friend ostream & operator<<(ostream &out, const mint &a) { return out << a.x; }
mint pow(long long e = M - 2) const {
mint ans = 1, b = *this;
while (e > 0) {
if (e % 2 == 1) {
ans *= b;
}
b *= b;
e /= 2;
}
return ans;
}
};
mint ways[N][N][L][3];
int a[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, l;
cin >> n >> l;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a, a + n);
if (n == 1) {
cout << 1 << "\n";
exit(0);
}
ways[0][0][0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= i; ++j) {
for (int k = 0; k <= l; ++k) {
for (int p = 0; p <= 2; ++p) {
int k_new = k + (2 * j - p) * (i > 0 ? a[i] - a[i - 1] : 0);
if (k_new > l || ways[i][j][k][p] == 0) {
continue;
}
if (j >= 2) {
ways[i + 1][j - 1][k_new][p] += (j - 1) * ways[i][j][k][p];
}
if (j >= 1) {
ways[i + 1][j][k_new][p] += (2 * j - p) * ways[i][j][k][p];
if (p < 2) {
ways[i + 1][j][k_new][p + 1] += (2 - p) * ways[i][j][k][p];
}
}
ways[i + 1][j + 1][k_new][p] += (j + 1 - p) * ways[i][j][k][p];
if (p < 2) {
ways[i + 1][j + 1][k_new][p + 1] += (2 - p) * ways[i][j][k][p];
}
}
}
}
}
mint ans = 0;
for (int i = 0; i <= l; ++i) {
ans += ways[n][1][i][2];
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
120132 KB |
Output is correct |
2 |
Correct |
61 ms |
120132 KB |
Output is correct |
3 |
Correct |
62 ms |
120096 KB |
Output is correct |
4 |
Correct |
61 ms |
120136 KB |
Output is correct |
5 |
Correct |
69 ms |
120128 KB |
Output is correct |
6 |
Correct |
69 ms |
120132 KB |
Output is correct |
7 |
Correct |
60 ms |
120108 KB |
Output is correct |
8 |
Correct |
62 ms |
120184 KB |
Output is correct |
9 |
Correct |
63 ms |
120132 KB |
Output is correct |
10 |
Correct |
63 ms |
120196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
120188 KB |
Output is correct |
2 |
Correct |
70 ms |
120152 KB |
Output is correct |
3 |
Correct |
68 ms |
120084 KB |
Output is correct |
4 |
Correct |
62 ms |
120072 KB |
Output is correct |
5 |
Correct |
62 ms |
120120 KB |
Output is correct |
6 |
Correct |
61 ms |
120176 KB |
Output is correct |
7 |
Correct |
62 ms |
120116 KB |
Output is correct |
8 |
Correct |
63 ms |
120152 KB |
Output is correct |
9 |
Correct |
63 ms |
120176 KB |
Output is correct |
10 |
Correct |
63 ms |
120132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
120132 KB |
Output is correct |
2 |
Correct |
61 ms |
120132 KB |
Output is correct |
3 |
Correct |
62 ms |
120096 KB |
Output is correct |
4 |
Correct |
61 ms |
120136 KB |
Output is correct |
5 |
Correct |
69 ms |
120128 KB |
Output is correct |
6 |
Correct |
69 ms |
120132 KB |
Output is correct |
7 |
Correct |
60 ms |
120108 KB |
Output is correct |
8 |
Correct |
62 ms |
120184 KB |
Output is correct |
9 |
Correct |
63 ms |
120132 KB |
Output is correct |
10 |
Correct |
63 ms |
120196 KB |
Output is correct |
11 |
Correct |
62 ms |
120188 KB |
Output is correct |
12 |
Correct |
70 ms |
120152 KB |
Output is correct |
13 |
Correct |
68 ms |
120084 KB |
Output is correct |
14 |
Correct |
62 ms |
120072 KB |
Output is correct |
15 |
Correct |
62 ms |
120120 KB |
Output is correct |
16 |
Correct |
61 ms |
120176 KB |
Output is correct |
17 |
Correct |
62 ms |
120116 KB |
Output is correct |
18 |
Correct |
63 ms |
120152 KB |
Output is correct |
19 |
Correct |
63 ms |
120176 KB |
Output is correct |
20 |
Correct |
63 ms |
120132 KB |
Output is correct |
21 |
Correct |
62 ms |
120216 KB |
Output is correct |
22 |
Correct |
140 ms |
120144 KB |
Output is correct |
23 |
Correct |
113 ms |
120316 KB |
Output is correct |
24 |
Correct |
106 ms |
120176 KB |
Output is correct |
25 |
Correct |
111 ms |
120196 KB |
Output is correct |
26 |
Correct |
101 ms |
120188 KB |
Output is correct |
27 |
Correct |
83 ms |
120260 KB |
Output is correct |
28 |
Correct |
90 ms |
120192 KB |
Output is correct |
29 |
Correct |
112 ms |
120196 KB |
Output is correct |
30 |
Correct |
108 ms |
120192 KB |
Output is correct |