#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n"
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
constexpr int MOD = 1e9+7;
int mult(int a,int b){
if(a*b>=MOD) return (a*b)%MOD;
return a*b;
}
int add(int a,int b){
if(a+b>=MOD) return a+b-MOD;
return a+b;
}
void solve(){
int n,l;
cin >> n >> l;
int ar[n+1];
for(int i=1;i<=n;i++) cin >> ar[i];
sort(ar+1,ar+n+1);
int dp[l+1][n+1][3];
int ndp[l+1][n+1][3];
memset(dp,0,sizeof(dp));
memset(ndp,0,sizeof(ndp));
dp[0][0][0]=1;
ar[0]=0;
if(n==1){
cout << 1 << endl;
return;
}
if(n==2){
if(ar[1]-ar[0]<=l) cout << 2 << endl;
else cout << 0 << endl;
return;
}
for(int i=1;i<=n;i++){
int c=ar[i]-ar[i-1];
for(int j=0;j<=n;j++){
for(int k=0;k<=l;k++){
for(int g=0;g<3;g++){
int nl=k+(2*j-g)*c;
if(nl>l) continue;
if(j+1<=n){ //new component
ndp[nl][j+1][g]=add(ndp[nl][j+1][g],mult(dp[k][j][g],j+1-g));
if(g==0){
ndp[nl][j+1][1]=add(ndp[nl][j+1][1],dp[k][j][0]);
ndp[nl][j+1][1]=add(ndp[nl][j+1][1],dp[k][j][0]);
}
else if(g==1){
ndp[nl][j+1][2]=add(ndp[nl][j+1][2],dp[k][j][1]);
}
}
ndp[nl][j][g]=add(ndp[nl][j][g],mult(dp[k][j][g],j*2-g));
if(g==0){
ndp[nl][j][1]=add(ndp[nl][j][1],dp[k][j][0]);
ndp[nl][j][1]=add(ndp[nl][j][1],dp[k][j][0]);
}
else if(g==1) ndp[nl][j][2]=add(ndp[nl][j][2],dp[k][j][1]);
if(j>=2) ndp[nl][j-1][g]=add(ndp[nl][j-1][g],mult(dp[k][j][g],j-1));
}
}
}
for(int j=0;j<=n;j++)
for(int k=0;k<=l;k++)
for(int g=0;g<3;g++) dp[k][j][g]=ndp[k][j][g];
memset(ndp,0,sizeof(ndp));
}
int ans=0;
for(int i=0;i<=l;i++) ans=add(ans,dp[i][1][2]);
cout << ans << endl;
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int t=1;//cin >> t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
552 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
552 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
116 ms |
3488 KB |
Output is correct |
23 |
Correct |
142 ms |
5208 KB |
Output is correct |
24 |
Correct |
126 ms |
3928 KB |
Output is correct |
25 |
Correct |
142 ms |
5348 KB |
Output is correct |
26 |
Correct |
118 ms |
4440 KB |
Output is correct |
27 |
Correct |
40 ms |
1368 KB |
Output is correct |
28 |
Correct |
56 ms |
1732 KB |
Output is correct |
29 |
Correct |
105 ms |
3164 KB |
Output is correct |
30 |
Correct |
145 ms |
5208 KB |
Output is correct |