#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int n, l;
int arr[102];
ll DP[102][102][1002][4];
ll ans;
inline void update(int i, int j, int k, int b, ll val){
if(1<=i && i<=n && 0<=j && j<=n && k<=l) DP[i][j][k][b] = (DP[i][j][k][b] + val) % MOD;
}
int main(){
scanf("%d %d", &n, &l);
if(n==1){
printf("1");
return 0;
}
for(int i=1; i<=n; i++){
scanf("%d", &arr[i]);
}
sort(arr+1, arr+n+1);
DP[1][1][0][0] = 1;
DP[1][0][0][1] = 1;
DP[1][0][0][2] = 1;
for(int i=1; i<n; i++){
for(int j=0; j<=i; j++){
for(int k=0; k<=l; k++){
for(int b=0; b<4; b++){
/// Place in the middle
int sideNum = 2*j + __builtin_popcount(b);
int val = k+sideNum*(arr[i+1] - arr[i]);
ll v = DP[i][j][k][b];
if(!v) continue;
if(i==n-1){
if(b==3 && j==0){
update(i+1, 0, k+2*(arr[i+1]-arr[i]), 3, v);
}
else if((b==1 || b==2) && j==0){
update(i+1, 0, k+(arr[i+1]-arr[i]), 3, v);
}
continue;
}
/// Case #1. This connects two components
update(i+1, j-1, val, b, v*(j-1+__builtin_popcount(b)));
/// Case #2. This does not change the number of coponents
update(i+1, j, val, b, v*sideNum);
/// Case #3. This is not connected by any other numbers
update(i+1, j+1, val, b, v*(j+1));
/// Place in the left
if(b==0 || b==2){ /// nothing is in the left
update(i+1, j, val, b|1, v); /// new start
if(j) update(i+1, j-1, val, b|1, v); /// connect
}
/// Place in the right
if(b==0 || b==1){ /// nothing is in the right
update(i+1, j, val, b|2, v); /// new start
if(j) update(i+1, j-1, val, b|2, v); /// connect
}
}
}
}
}
// for(int i=1; i<=n; i++) for(int j=0; j<=n; j++) for(int k=0; k<=l; k++) for(int b=0; b<4; b++){
// printf("%d %d %d %d -> %lld\n", i, j, k, b, DP[i][j][k][b]);
// }
for(int i=0; i<=l; i++){
ans += DP[n][0][i][3];
ans %= MOD;
}
printf("%lld", ans);
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
18 | scanf("%d %d", &n, &l);
| ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
25 | scanf("%d", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
640 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
768 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
2 ms |
1408 KB |
Output is correct |
22 |
Correct |
149 ms |
30584 KB |
Output is correct |
23 |
Correct |
126 ms |
10920 KB |
Output is correct |
24 |
Correct |
119 ms |
15732 KB |
Output is correct |
25 |
Correct |
132 ms |
12524 KB |
Output is correct |
26 |
Correct |
119 ms |
11384 KB |
Output is correct |
27 |
Correct |
55 ms |
11640 KB |
Output is correct |
28 |
Correct |
65 ms |
14512 KB |
Output is correct |
29 |
Correct |
140 ms |
20856 KB |
Output is correct |
30 |
Correct |
132 ms |
12664 KB |
Output is correct |