#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll ll>
#define st first
#define nd second
#define pb push_back
using namespace std;
const int maxN = 1e2 + 2;
const int maxL = 1e3 + 2;
const int M = 1e9 + 7;
ll dp[maxN][10*maxL][3], tmp[maxN][10*maxL][3], a[maxN];
void solve() {
ll n, l; cin >> n >> l;
if (n == 1) {
cout << 1 << '\n';
return;
}
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a+1, a+n+1);
tmp[0][5*l][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int k = 0; k <= 10*l; ++k) {
if (k+2*a[i] <= 10*l) {
dp[j][k][0] = (dp[j][k][0] + j*tmp[j-1][k+2*a[i]][0]) % M;
dp[j][k][1] = (dp[j][k][1] + (j-1)*tmp[j-1][k+2*a[i]][1]) % M;
dp[j][k][2] = (dp[j][k][2] + (j-2)*tmp[j-1][k+2*a[i]][2]) % M;
}
if (k+a[i] <= 10*l) {
dp[j][k][1] = (dp[j][k][1] + 2*tmp[j-1][k+a[i]][0]) % M;
dp[j][k][2] = (dp[j][k][2] + tmp[j-1][k+a[i]][1]) % M;
}
dp[j][k][0] = (dp[j][k][0] + (2*j)*tmp[j][k][0]) % M;
dp[j][k][1] = (dp[j][k][1] + (2*j-1)*tmp[j][k][1]) % M;
dp[j][k][2] = (dp[j][k][2] + (2*j-2)*tmp[j][k][2]) % M;
if (k-a[i] >= 0) {
dp[j][k][1] = (dp[j][k][1] + 2*tmp[j][k-a[i]][0]) % M;
dp[j][k][2] = (dp[j][k][2] + tmp[j][k-a[i]][1]) % M;
}
if (k-2*a[i] >= 0) {
dp[j][k][0] = (dp[j][k][0] + j*tmp[j+1][k-2*a[i]][0]) % M;
dp[j][k][1] = (dp[j][k][1] + j*tmp[j+1][k-2*a[i]][1]) % M;
dp[j][k][2] = (dp[j][k][2] + j*tmp[j+1][k-2*a[i]][2]) % M;
}
}
}
for (int j = 0; j <= n; ++j) {
for (int k = 0; k <= 10*l; ++k) {
tmp[j][k][0] = dp[j][k][0];
tmp[j][k][1] = dp[j][k][1];
tmp[j][k][2] = dp[j][k][2];
dp[j][k][0] = dp[j][k][1] = dp[j][k][2] = 0;
}
}
}
ll ans = 0;
for (int i = 5*l; i <= 6*l; ++i) {
ans += tmp[1][i][2];
ans %= M;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
14 ms |
4444 KB |
Output is correct |
6 |
Correct |
14 ms |
4108 KB |
Output is correct |
7 |
Correct |
3 ms |
1112 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
17 ms |
4144 KB |
Output is correct |
10 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
5 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
5 ms |
1116 KB |
Output is correct |
5 |
Correct |
5 ms |
1156 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
4 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
14 ms |
4444 KB |
Output is correct |
6 |
Correct |
14 ms |
4108 KB |
Output is correct |
7 |
Correct |
3 ms |
1112 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
17 ms |
4144 KB |
Output is correct |
10 |
Correct |
2 ms |
856 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
5 ms |
1116 KB |
Output is correct |
15 |
Correct |
5 ms |
1156 KB |
Output is correct |
16 |
Correct |
5 ms |
1116 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
3 ms |
860 KB |
Output is correct |
20 |
Correct |
4 ms |
1116 KB |
Output is correct |
21 |
Correct |
14 ms |
1372 KB |
Output is correct |
22 |
Correct |
1172 ms |
31580 KB |
Output is correct |
23 |
Execution timed out |
2097 ms |
47696 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |