// IOI 2021
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
////////////////////////////////////////////////////////////////////
const int N = 1e2 + 5, L = 1e3 + 5;
int A[N], DP[N][N][L][3];
void Add(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
int SMul(int x, int y) { return 1LL * x * y % MOD; }
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
mt19937 Rnd(time(0));
int n, l; cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> A[i];
if (n == 1) die(1);
sort(A + 1, A + n + 1);
DP[1][0][0][1] = 2, DP[1][0][0][2] = 1;
for (int i = 1; i <= n; i++) for (int j = 0; j <= i; j++) for (int s = 0; s <= l; s++) for (int c = 0; c < 3; c++) {
int x = A[i + 1] - A[i], y = 2 * j + c, d = s + x * y, p = DP[i][j][s][c];
if (d >= L || j + c == 0) continue;
if (j) {
Add(DP[i + 1][j - 1][d][c], SMul(j, p));
Add(DP[i + 1][j][d][c], SMul(j << 1, p));
Add(DP[i + 1][j + 1][d][c], SMul(j, p));
}
if (c) {
Add(DP[i + 1][j][d][c - 1], SMul(c, p));
Add(DP[i + 1][j][d][c], SMul(c, p));
Add(DP[i + 1][j + 1][d][c - 1], SMul(c, p));
Add(DP[i + 1][j + 1][d][c], SMul(c, p));
}
}
int ans = 0;
for (int i = 0; i <= l; i++) Add(ans, DP[n][0][i][0]);
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
896 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1024 KB |
Output is correct |
4 |
Correct |
6 ms |
1152 KB |
Output is correct |
5 |
Correct |
6 ms |
1280 KB |
Output is correct |
6 |
Correct |
6 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
5 ms |
1024 KB |
Output is correct |
9 |
Correct |
5 ms |
1024 KB |
Output is correct |
10 |
Correct |
5 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
896 KB |
Output is correct |
12 |
Correct |
6 ms |
1152 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
14 |
Correct |
6 ms |
1152 KB |
Output is correct |
15 |
Correct |
6 ms |
1280 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1024 KB |
Output is correct |
18 |
Correct |
5 ms |
1024 KB |
Output is correct |
19 |
Correct |
5 ms |
1024 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
21 |
Correct |
8 ms |
4608 KB |
Output is correct |
22 |
Correct |
116 ms |
38648 KB |
Output is correct |
23 |
Correct |
136 ms |
46076 KB |
Output is correct |
24 |
Correct |
157 ms |
54520 KB |
Output is correct |
25 |
Correct |
147 ms |
45764 KB |
Output is correct |
26 |
Correct |
145 ms |
48504 KB |
Output is correct |
27 |
Correct |
73 ms |
37244 KB |
Output is correct |
28 |
Correct |
85 ms |
40568 KB |
Output is correct |
29 |
Correct |
143 ms |
56824 KB |
Output is correct |
30 |
Correct |
138 ms |
45688 KB |
Output is correct |