#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e2;
const int L = 1e3;
const ll MOD = 1e9+7;
ll dmod(ll x){
return x%MOD;
}
int n,l;
int a[N+5];
int memo[N+2][N+2][L+2][3];
int dp(int x, int cc, int sisa, int tepi){
if(sisa < 0) return 0;
// printf(">> %d %d %d %d\n", x, cc, sisa, tepi);
if(x > n){
if(tepi == 2 && cc == 1) return 1;
return 0;
}
if(tepi == 2 && cc == 1) return 0;
int &ret = memo[x][cc][sisa][tepi];
if(ret != -1) return ret;
ret = 0;
// nambah cc
ret = dmod(ret + dmod((ll)(cc+1ll - tepi) * dp(x+1,cc+1,sisa-(2*(cc+1) - tepi)*(a[x+1]-a[x]),tepi)));
if(tepi < 2) ret = dmod(ret + dmod((ll)(2ll-tepi)*dp(x+1,cc+1,sisa-(2*(cc+1) - tepi - 1)*(a[x+1]-a[x]),tepi+1)));
// kiri kanan cc
ret = dmod(ret + dmod((ll)(2ll*cc-tepi) * dp(x+1, cc, sisa-(2*cc - tepi)*(a[x+1]-a[x]),tepi)));
if(tepi < 2 && cc > 0) ret = dmod(ret + dmod((ll)(2ll-tepi)*dp(x+1,cc,sisa-(2*cc - tepi - 1)*(a[x+1]-a[x]),tepi+1)));
// join cc
if(cc >= 2) ret = dmod(ret + dmod((ll)(cc-1ll)*dp(x+1, cc-1, sisa-(2*(cc-1) - tepi)*(a[x+1]-a[x]), tepi)));
// printf(">> %d %d %d %d = %d\n", x, cc, sisa, tepi, ret);
return ret;
}
int main(){
memset(memo,-1,sizeof(memo));
scanf("%d%d",&n,&l);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+1,a+n+1);
a[n+1] = a[n];
int ans = dp(1,0,l,0);
if(n == 1) ans = 1;
printf("%d\n",ans);
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d",&n,&l);
| ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
122612 KB |
Output is correct |
2 |
Correct |
45 ms |
122576 KB |
Output is correct |
3 |
Correct |
46 ms |
122648 KB |
Output is correct |
4 |
Correct |
45 ms |
122708 KB |
Output is correct |
5 |
Correct |
45 ms |
122580 KB |
Output is correct |
6 |
Correct |
44 ms |
122676 KB |
Output is correct |
7 |
Correct |
44 ms |
122580 KB |
Output is correct |
8 |
Correct |
48 ms |
122584 KB |
Output is correct |
9 |
Correct |
51 ms |
122576 KB |
Output is correct |
10 |
Correct |
44 ms |
122608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
122740 KB |
Output is correct |
2 |
Correct |
45 ms |
122572 KB |
Output is correct |
3 |
Correct |
44 ms |
122784 KB |
Output is correct |
4 |
Correct |
46 ms |
122584 KB |
Output is correct |
5 |
Correct |
45 ms |
122640 KB |
Output is correct |
6 |
Correct |
45 ms |
122632 KB |
Output is correct |
7 |
Correct |
46 ms |
122608 KB |
Output is correct |
8 |
Correct |
47 ms |
122660 KB |
Output is correct |
9 |
Correct |
46 ms |
122668 KB |
Output is correct |
10 |
Correct |
49 ms |
122572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
122612 KB |
Output is correct |
2 |
Correct |
45 ms |
122576 KB |
Output is correct |
3 |
Correct |
46 ms |
122648 KB |
Output is correct |
4 |
Correct |
45 ms |
122708 KB |
Output is correct |
5 |
Correct |
45 ms |
122580 KB |
Output is correct |
6 |
Correct |
44 ms |
122676 KB |
Output is correct |
7 |
Correct |
44 ms |
122580 KB |
Output is correct |
8 |
Correct |
48 ms |
122584 KB |
Output is correct |
9 |
Correct |
51 ms |
122576 KB |
Output is correct |
10 |
Correct |
44 ms |
122608 KB |
Output is correct |
11 |
Correct |
45 ms |
122740 KB |
Output is correct |
12 |
Correct |
45 ms |
122572 KB |
Output is correct |
13 |
Correct |
44 ms |
122784 KB |
Output is correct |
14 |
Correct |
46 ms |
122584 KB |
Output is correct |
15 |
Correct |
45 ms |
122640 KB |
Output is correct |
16 |
Correct |
45 ms |
122632 KB |
Output is correct |
17 |
Correct |
46 ms |
122608 KB |
Output is correct |
18 |
Correct |
47 ms |
122660 KB |
Output is correct |
19 |
Correct |
46 ms |
122668 KB |
Output is correct |
20 |
Correct |
49 ms |
122572 KB |
Output is correct |
21 |
Correct |
45 ms |
122672 KB |
Output is correct |
22 |
Correct |
154 ms |
122696 KB |
Output is correct |
23 |
Correct |
103 ms |
122696 KB |
Output is correct |
24 |
Correct |
112 ms |
122704 KB |
Output is correct |
25 |
Correct |
108 ms |
122700 KB |
Output is correct |
26 |
Correct |
104 ms |
122700 KB |
Output is correct |
27 |
Correct |
74 ms |
122692 KB |
Output is correct |
28 |
Correct |
79 ms |
122640 KB |
Output is correct |
29 |
Correct |
131 ms |
122700 KB |
Output is correct |
30 |
Correct |
115 ms |
122676 KB |
Output is correct |