#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=105;
const int mod=1e9+7;
int n,L,a[N],b[N];
int dp[N][N][2][2][N*10];
int calc(int i,int cnt,bool haveL,bool haveR,int val)
{
if(i) val+=a[i-1]*(2*cnt-haveL-haveR);
if(val>L) return 0;
int &res=dp[i][cnt][haveL][haveR][val];
if(res!=-1) return res;
if(i==n)
{
if(val>L||cnt!=1||!haveL||!haveR) return 0;
return 1;
}
res=0;
///new comp
(res+=calc(i+1,cnt+1,haveL,haveR,val)*(cnt+1-haveL-haveR)%mod)%=mod;
///new L
if(!haveL) (res+=calc(i+1,cnt+1,1,haveR,val))%=mod;
///new R
if(!haveR) (res+=calc(i+1,cnt+1,haveL,1,val))%=mod;
if(cnt)
{
///merge
if(cnt>=2) (res+=calc(i+1,cnt-1,haveL,haveR,val)*(cnt-1)%mod)%=mod;
///push front
(res+=calc(i+1,cnt,haveL,haveR,val)*(cnt-haveL)%mod)%=mod;
///push back
(res+=calc(i+1,cnt,haveL,haveR,val)*(cnt-haveR)%mod)%=mod;
///made L
if(!haveL) (res+=calc(i+1,cnt,1,haveR,val))%=mod;
///made R
if(!haveR) (res+=calc(i+1,cnt,haveL,1,val))%=mod;
}
//cout<<i<<' '<<cnt<<' '<<haveL<<' '<<haveR<<' '<<val<<'\n' ;
return res;
}
main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
memset(dp,-1,sizeof dp);
cin>>n>>L;
if(n==1) return cout<<1,0;
for(int i=0;i<n;i++) cin>>b[i];
sort(b,b+n);
for(int i=0;i<n;i++) a[i]=b[i+1]-b[i];
cout<<calc(0,0,0,0,0);
}
Compilation message
skyscraper.cpp:46:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main()
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
362848 KB |
Output is correct |
2 |
Correct |
199 ms |
362876 KB |
Output is correct |
3 |
Correct |
195 ms |
362744 KB |
Output is correct |
4 |
Correct |
197 ms |
362744 KB |
Output is correct |
5 |
Correct |
197 ms |
362872 KB |
Output is correct |
6 |
Correct |
196 ms |
362820 KB |
Output is correct |
7 |
Correct |
195 ms |
362744 KB |
Output is correct |
8 |
Correct |
198 ms |
362872 KB |
Output is correct |
9 |
Correct |
195 ms |
362744 KB |
Output is correct |
10 |
Correct |
196 ms |
362744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
362740 KB |
Output is correct |
2 |
Correct |
212 ms |
362748 KB |
Output is correct |
3 |
Correct |
203 ms |
362872 KB |
Output is correct |
4 |
Correct |
199 ms |
362760 KB |
Output is correct |
5 |
Correct |
197 ms |
362744 KB |
Output is correct |
6 |
Correct |
201 ms |
362808 KB |
Output is correct |
7 |
Correct |
200 ms |
362872 KB |
Output is correct |
8 |
Correct |
200 ms |
362868 KB |
Output is correct |
9 |
Correct |
197 ms |
362744 KB |
Output is correct |
10 |
Correct |
197 ms |
362872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
362848 KB |
Output is correct |
2 |
Correct |
199 ms |
362876 KB |
Output is correct |
3 |
Correct |
195 ms |
362744 KB |
Output is correct |
4 |
Correct |
197 ms |
362744 KB |
Output is correct |
5 |
Correct |
197 ms |
362872 KB |
Output is correct |
6 |
Correct |
196 ms |
362820 KB |
Output is correct |
7 |
Correct |
195 ms |
362744 KB |
Output is correct |
8 |
Correct |
198 ms |
362872 KB |
Output is correct |
9 |
Correct |
195 ms |
362744 KB |
Output is correct |
10 |
Correct |
196 ms |
362744 KB |
Output is correct |
11 |
Correct |
200 ms |
362740 KB |
Output is correct |
12 |
Correct |
212 ms |
362748 KB |
Output is correct |
13 |
Correct |
203 ms |
362872 KB |
Output is correct |
14 |
Correct |
199 ms |
362760 KB |
Output is correct |
15 |
Correct |
197 ms |
362744 KB |
Output is correct |
16 |
Correct |
201 ms |
362808 KB |
Output is correct |
17 |
Correct |
200 ms |
362872 KB |
Output is correct |
18 |
Correct |
200 ms |
362868 KB |
Output is correct |
19 |
Correct |
197 ms |
362744 KB |
Output is correct |
20 |
Correct |
197 ms |
362872 KB |
Output is correct |
21 |
Correct |
199 ms |
362744 KB |
Output is correct |
22 |
Correct |
571 ms |
362744 KB |
Output is correct |
23 |
Correct |
292 ms |
362744 KB |
Output is correct |
24 |
Correct |
341 ms |
362744 KB |
Output is correct |
25 |
Correct |
317 ms |
362800 KB |
Output is correct |
26 |
Correct |
307 ms |
362744 KB |
Output is correct |
27 |
Correct |
271 ms |
362784 KB |
Output is correct |
28 |
Correct |
308 ms |
363000 KB |
Output is correct |
29 |
Correct |
423 ms |
362872 KB |
Output is correct |
30 |
Correct |
313 ms |
362872 KB |
Output is correct |