This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define MAXN 110
#define MAXL 1010
#define MOD 1000000007
using namespace std;
ll a[MAXN],dp[MAXN][MAXN][MAXL][3];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,l;
    cin >> n >> l;
    for (ll i=1;i<=n;i++)
        cin >> a[i];
    sort(a+1,a+1+n);
    a[n+1]=a[n];
    dp[0][0][0][0]=1;
    for (ll i=1;i<=n;i++)
    {
        for (ll j=1;j<=i;j++)
        {
            for (ll cost=0;cost<=l;cost++)
            {
                for (ll ends=0;ends<3;ends++)
                {
                    ll C=(2*j-ends)*(a[i+1]-a[i]);
                    if (C>cost)
                        continue;
                    dp[i][j][cost][ends]+=dp[i-1][j-1][cost-C][ends];
                    dp[i][j][cost][ends]%=MOD;
                    dp[i][j][cost][ends]+=dp[i-1][j][cost-C][ends]*(2*j-ends);
                    dp[i][j][cost][ends]%=MOD;
                    if (ends)
                    {
                        dp[i][j][cost][ends]+=dp[i-1][j-1][cost-C][ends-1]*(3-ends);
                        dp[i][j][cost][ends]%=MOD;
                        if (ends==1)
                            dp[i][j][cost][ends]+=dp[i-1][j][cost-C][ends-1]*2*j;
                        if (ends==2)
                        {
                            if (j==1 && i==n)
                                dp[i][j][cost][ends]+=dp[i-1][j][cost-C][ends-1];
                            else if (j>1)
                                dp[i][j][cost][ends]+=dp[i-1][j][cost-C][ends-1]*(j-1);
                        }
                        dp[i][j][cost][ends]%=MOD;
                    }
                    if (!ends)
                        dp[i][j][cost][ends]+=dp[i-1][j+1][cost-C][ends]*j*(j+1);
                    if (ends==1)
                        dp[i][j][cost][ends]+=dp[i-1][j+1][cost-C][ends]*j*j;
                    if (ends==2)
                    {
                        if (j==1 && i==n)
                            dp[i][j][cost][ends]+=dp[i-1][j+1][cost-C][ends];
                        else if (j>1)
                            dp[i][j][cost][ends]+=dp[i-1][j+1][cost-C][ends]*j*(j-1);
                    }
                    dp[i][j][cost][ends]%=MOD;
                }
            }
        }
    }
    ll ans=0;
    for (ll i=0;i<=l;i++)
        ans=(ans+dp[n][1][i][2])%MOD;
    cout << (n==1?1 : ans);
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |