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<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
ll n,L,a[110];
ll dp[110][2][2][110][1010];
ll dq[110][2][2][110];
void ad(ll i,ll l,ll r,ll c,ll cost,ll val){
ll id=cost-dq[i][l][r][c];
if(id<L){
mad(dp[i][l][r][c][id],val);
}
}
int main(){
cin>>n>>L;
rep(i,n)cin>>a[i];
sort(a,a+n);
if(n==1){
cout<<1<<endl;
return 0;
}
rep(i,n)rep(l,2)rep(r,2)rep(c,n)dq[i][l][r][c]=1e17;
dq[0][0][0][1]=-2*a[0];
dq[0][0][1][1]=-1*a[0];
dq[0][1][0][1]=-1*a[0];
rep(i,n-1)rep(l,2)rep(r,2)rep(c,n){
if(l==1&&r==1&&c==1)continue;
ll cost=dq[i][l][r][c];
if(c+1>=1)chmin(dq[i+1][l][r][c+1],cost-2*a[i+1]);
if(c+0>=1)chmin(dq[i+1][l][r][c+0],cost);
if(c-1>=1)chmin(dq[i+1][l][r][c-1],cost+2*a[i+1]);
if(l==0){
if(c+1>=1)chmin(dq[i+1][1][r][c+1],cost-a[i+1]);
if(c+0>=1)chmin(dq[i+1][1][r][c+0],cost+a[i+1]);
}
if(r==0){
if(c+1>=1)chmin(dq[i+1][l][1][c+1],cost-a[i+1]);
if(c+0>=1)chmin(dq[i+1][l][1][c+0],cost+a[i+1]);
}
}
rep(i,n)rep(l,2)rep(r,2)rep(c,n)rep(cost,L)dp[i][l][r][c][cost]=0;
dp[0][0][0][1][-2*a[0]-dq[0][0][0][1]]=1;
dp[0][0][1][1][-1*a[0]-dq[0][0][1][1]]=1;
dp[0][1][0][1][-1*a[0]-dq[0][1][0][1]]=1;
rep(i,n-1)rep(l,2)rep(r,2)rep(c,n)rep(cosyo,L){
if(l==1&&r==1&&c==1)continue;
ll cost=dq[i][l][r][c]+cosyo;
ll val=dp[i][l][r][c][cosyo];
if(c+1>=1)ad(i+1,l,r,c+1,cost-2*a[i+1],val*(c+1-l-r));
if(c+0>=1)ad(i+1,l,r,c+0,cost,val*(c*2-l-r));
if(c-1>=1)ad(i+1,l,r,c-1,cost+2*a[i+1],val*(c-1));
if(l==0){
if(c+1>=1)ad(i+1,1,r,c+1,cost-a[i+1],val);
if(c+0>=1)ad(i+1,1,r,c+0,cost+a[i+1],val);
}
if(r==0){
if(c+1>=1)ad(i+1,l,1,c+1,cost-a[i+1],val);
if(c+0>=1)ad(i+1,l,1,c+0,cost+a[i+1],val);
}
}
ll ans=0;
rep(cosyo,L){
ll cost=dq[n-1][1][1][1]+cosyo;
if(cost<=L)mad(ans,dp[n-1][1][1][1][cosyo]);
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |