#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=1e2+10, maxm=1e3+10, lg=21, mod=1e9+7, inf=1e18;
ll n,L,a[maxn],dp[maxn][maxn][maxm][3];
ll moz(ll i,ll cc,ll sum,ll tend){
if(sum>L || (cc==0 && i!=1)) return 0;
if(i==n+1) return tend==2 && cc==1;
ll &x=dp[i][cc][sum][tend];
if(x!=-1) return x;
x=0;
sum+=(a[i]-a[i-1])*(2*cc-tend);
if(cc>=1) x+=(2*cc-tend)*moz(i+1,cc,sum,tend); // merge1
if(cc>=2) x+=(cc-1)*moz(i+1,cc-1,sum,tend); // merge2
x+=(cc+1-tend)*moz(i+1,cc+1,sum,tend); // mostaghel vasat
if(tend<2){
x+=(2-tend)*moz(i+1,cc+1,sum,tend+1); // mostaghel end
x+=(2-tend)*moz(i+1,cc,sum,tend+1); // bechasbe be tah bokone end
}
return x%=mod;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>L;
if(n==1) return cout<<1,0;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
memset(dp,-1,sizeof(dp));
cout<<moz(1,0,0,0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
142 ms |
287352 KB |
Output is correct |
3 |
Correct |
144 ms |
287352 KB |
Output is correct |
4 |
Correct |
147 ms |
287352 KB |
Output is correct |
5 |
Correct |
146 ms |
287352 KB |
Output is correct |
6 |
Correct |
145 ms |
287352 KB |
Output is correct |
7 |
Correct |
148 ms |
287352 KB |
Output is correct |
8 |
Correct |
153 ms |
287348 KB |
Output is correct |
9 |
Correct |
146 ms |
287356 KB |
Output is correct |
10 |
Correct |
146 ms |
287352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
287352 KB |
Output is correct |
2 |
Correct |
145 ms |
287352 KB |
Output is correct |
3 |
Correct |
151 ms |
287352 KB |
Output is correct |
4 |
Correct |
147 ms |
287336 KB |
Output is correct |
5 |
Correct |
145 ms |
287352 KB |
Output is correct |
6 |
Correct |
147 ms |
287352 KB |
Output is correct |
7 |
Correct |
145 ms |
287352 KB |
Output is correct |
8 |
Correct |
145 ms |
287352 KB |
Output is correct |
9 |
Correct |
143 ms |
287352 KB |
Output is correct |
10 |
Correct |
146 ms |
287352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
142 ms |
287352 KB |
Output is correct |
3 |
Correct |
144 ms |
287352 KB |
Output is correct |
4 |
Correct |
147 ms |
287352 KB |
Output is correct |
5 |
Correct |
146 ms |
287352 KB |
Output is correct |
6 |
Correct |
145 ms |
287352 KB |
Output is correct |
7 |
Correct |
148 ms |
287352 KB |
Output is correct |
8 |
Correct |
153 ms |
287348 KB |
Output is correct |
9 |
Correct |
146 ms |
287356 KB |
Output is correct |
10 |
Correct |
146 ms |
287352 KB |
Output is correct |
11 |
Correct |
144 ms |
287352 KB |
Output is correct |
12 |
Correct |
145 ms |
287352 KB |
Output is correct |
13 |
Correct |
151 ms |
287352 KB |
Output is correct |
14 |
Correct |
147 ms |
287336 KB |
Output is correct |
15 |
Correct |
145 ms |
287352 KB |
Output is correct |
16 |
Correct |
147 ms |
287352 KB |
Output is correct |
17 |
Correct |
145 ms |
287352 KB |
Output is correct |
18 |
Correct |
145 ms |
287352 KB |
Output is correct |
19 |
Correct |
143 ms |
287352 KB |
Output is correct |
20 |
Correct |
146 ms |
287352 KB |
Output is correct |
21 |
Correct |
145 ms |
287352 KB |
Output is correct |
22 |
Correct |
214 ms |
287368 KB |
Output is correct |
23 |
Correct |
182 ms |
287292 KB |
Output is correct |
24 |
Correct |
218 ms |
287352 KB |
Output is correct |
25 |
Correct |
183 ms |
287352 KB |
Output is correct |
26 |
Correct |
177 ms |
287352 KB |
Output is correct |
27 |
Correct |
204 ms |
287308 KB |
Output is correct |
28 |
Correct |
169 ms |
287364 KB |
Output is correct |
29 |
Correct |
196 ms |
287352 KB |
Output is correct |
30 |
Correct |
187 ms |
287352 KB |
Output is correct |