#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
#pragma warning(disable : 4996)
const int N = 101, S = 2e5 + 1, MOD = 1e9 + 7;
int a[N], b[N], dp[2][3][N][S];
void f(int &a, int b) {
a += b;
while (a >= MOD)
a -= MOD;
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, l;
cin >> n >> l;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
reverse(a, a + n);
for (int i = 0; i < n; i++) {
a[i] -= a[n - 1];
}
for (int i = n - 1; i >= 0; i--) {
b[i] += b[i + 1] + a[i];
}
dp[1][0][0][0] = 1;
dp[1][2][0][a[0] + a[0]] = 1;
dp[1][1][0][a[0]] = 2;
for (int i = 1, q = 1; i < n; i++, q ^= 1) {
int mx = b[i + 1] * 2 + l;
for (int x = 0; x < 3; x++) {
for (int j = 0; j < min(i, n - i + 1); j++) {
for (int k = 0; k <= (a[i - 1] << 1); k++) {
if (dp[q][x][j][k]) {
int cur = dp[q][x][j][k];
if (x) {
int cur2 = cur * x;
if (cur2 >= MOD)
cur2 -= MOD;
f(dp[q ^ 1][x - 1][j][k - a[i]], cur2);
f(dp[q ^ 1][x][j][k], cur2);
if (k + a[i] <= mx)
f(dp[q ^ 1][x - 1][j + 1][k + a[i]], cur2);
if (k + a[i] + a[i] <= mx)
f(dp[q ^ 1][x][j + 1][k + a[i] + a[i]], cur2);
}
cur = cur * (ll)j;
while (cur >= MOD)
cur -= MOD;
if (j) {
int cur2 = cur + cur;
if (cur2 >= MOD)
cur2 -= MOD;
f(dp[q ^ 1][x][j][k], cur2);
if (k + a[i] + a[i] <= mx)
f(dp[q ^ 1][x][j + 1][k + a[i] + a[i]], cur);
f(dp[q ^ 1][x][j - 1][k - a[i] - a[i]], cur);
}
dp[q][x][j][k] = 0;
}
}
}
}
a[i] += a[i - 1];
}
int ans = 0;
for (int i = 0; i <= l; i++) {
f(ans, dp[n & 1][0][0][i]);
}
cout << ans;
return 0;
}
Compilation message
skyscraper.cpp:41:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable : 4996)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
0 ms |
512 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
7 ms |
1024 KB |
Output is correct |
22 |
Incorrect |
102 ms |
2752 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |