#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;
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |