#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"
void setIO() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
}
const int MOD = 1e9+7;
int n, l, a[101];
int dp[101][101][1010][3];
void ADD(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }
int mul(int a, int b) { return 1LL * a * b % MOD; }
int main() {
setIO();
cin >> n >> l;
foru(i, 1, n) cin >> a[i];
sort(a+1, a+n+1);
if (n == 1) {
cout << 1;
return 0;
}
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
foru(i, 1, n-1) {
int value = a[i+1];
foru(cc, 0, i)
foru(cost, 0, l)
foru(end, 0, 2) {
int cur = dp[i][cc][cost][end];
if (cur == 0) continue;
// cout << "process " << i << " elements\n";
// cout << "num cc " << cc << "\n";
// cout << "cost " << cost << "\n";
// cout << "endpoint filled " << end << "\n";
// cout << cur << "\n";
// cout << "-------\n";
int nx_cost = cost + (a[i+1] - a[i]) * (cc * 2 - end);
// cout << nx_cost << "\n";
if (nx_cost > l) continue;
// new cc at endpoint
if (end < 2) ADD(dp[i+1][cc+1][nx_cost][end+1], mul(cur, 2 - end));
// append cc with endpoint
if (end < 2 && cc >= 1) ADD(dp[i+1][cc][nx_cost][end+1], mul(cur, 2 - end));
// place in the middle
ADD(dp[i+1][cc+1][nx_cost][end], mul(cur, cc + 1 - end));
// append two cc
if (cc >= 2) ADD(dp[i+1][cc-1][nx_cost][end], mul(cur, cc-1));
// place left or right of cc
if (cc >= 1) ADD(dp[i+1][cc][nx_cost][end], mul(cur, 2*cc-end));
}
}
// cout << dp[2][2][2][1] << "\n";
int ans = 0;
foru(i, 0, l) ADD(ans, dp[n][1][i][2]);
cout << ans;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:47:9: warning: unused variable 'value' [-Wunused-variable]
47 | int value = a[i+1];
| ^~~~~
skyscraper.cpp: In function 'void setIO()':
skyscraper.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(file".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(file".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2764 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2904 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2764 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2904 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
3416 KB |
Output is correct |
22 |
Correct |
31 ms |
18256 KB |
Output is correct |
23 |
Correct |
32 ms |
8284 KB |
Output is correct |
24 |
Correct |
21 ms |
11336 KB |
Output is correct |
25 |
Correct |
21 ms |
9048 KB |
Output is correct |
26 |
Correct |
19 ms |
8804 KB |
Output is correct |
27 |
Correct |
16 ms |
10332 KB |
Output is correct |
28 |
Correct |
23 ms |
11860 KB |
Output is correct |
29 |
Correct |
29 ms |
14420 KB |
Output is correct |
30 |
Correct |
21 ms |
9304 KB |
Output is correct |