#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
vvv() {}
};
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 1e9 + 7, N = 200001, logC = 30;
int dp[101][101][1001][3];
void add(int &i, int j) {
i += j;
if (i >= mod)
i -= mod;
}
int main () {
owo;
int n, l;
cin >> n >> l;
vector <int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (n == 1) {
cout << 1 << endl;
return 0;
}
sort(all(a));
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
for (int i = 1; i < n; ++i) for (int val = 0; val <= l; ++val) for (int j = 0; j < 3; ++j) for (int cc = 1; cc < n; ++cc) {
int nxtcost = val + (a[i] - a[i - 1]) * (cc * 2 - j);
if (nxtcost > l)
continue;
test(nxtcost);
if (dp[i][cc][val][j])
test(i, cc, val, j, dp[i][cc][val][j]);
// add one group
add(dp[i + 1][cc + 1][nxtcost][j], 1ll * dp[i][cc][val][j] * (cc + 1 - j) % mod);
// append to one's end
add(dp[i + 1][cc][nxtcost][j], 1ll * dp[i][cc][val][j] * (cc * 2 - j) % mod);
// glue two cc
add(dp[i + 1][cc - 1][nxtcost][j], 1ll * dp[i][cc][val][j] * (cc - 1) % mod);
// put one side
if (j < 2) {
// add one group
add(dp[i + 1][cc + 1][nxtcost][j + 1], dp[i][cc][val][j] * (j ? 1 : 2) % mod);
// append to one's end
add(dp[i + 1][cc][nxtcost][j + 1], dp[i][cc][val][j] * (j ? 1 : 2) % mod);
}
}
int ans = 0;
for (int i = 0; i <= l; ++i)
add(ans, dp[n][1][i][2]), test(i, dp[n][1][i][2]);
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
844 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1228 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Correct |
1 ms |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
972 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1228 KB |
Output is correct |
20 |
Correct |
1 ms |
972 KB |
Output is correct |
21 |
Correct |
3 ms |
4044 KB |
Output is correct |
22 |
Correct |
233 ms |
71224 KB |
Output is correct |
23 |
Correct |
239 ms |
69160 KB |
Output is correct |
24 |
Correct |
223 ms |
78020 KB |
Output is correct |
25 |
Correct |
241 ms |
70596 KB |
Output is correct |
26 |
Correct |
222 ms |
69232 KB |
Output is correct |
27 |
Correct |
99 ms |
57816 KB |
Output is correct |
28 |
Correct |
126 ms |
64396 KB |
Output is correct |
29 |
Correct |
219 ms |
84284 KB |
Output is correct |
30 |
Correct |
255 ms |
70268 KB |
Output is correct |