#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
typedef long long ll;
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;
#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (106)
ll n,L,dp[106][106][2][2][1006],A[106],mod=1e9+7;
int main(){
FAST
cin>>n>>L;
FOR(i,1,n)cin>>A[i];
sort(A+1,A+n+1);
if(n==1){
return cout<<1, 0;
}
if(n==2){
if(A[2]-A[1] <= L) return cout<<2, 0;
else return cout<<0, 0;
}
dp[0][0][0][0][0]=1;
FOR(i,1,n-1)FOR(c,1,i)FOR(s,0,1)FOR(e,0,1)FOR(l,0,L){
ll diff=A[i]-A[i-1];
if(l-diff*((c+1-s-e)*2+s+e)>=0) dp[i][c][s][e][l] += dp[i-1][c+1][s][e][l-diff*((c+1-s-e)*2+s+e)]
* (((c+1) * c - (e?c:0) - (s?c:0))%mod)%mod,dp[i][c][s][e][l]%=mod; // +(s&&e)-(s&&e)
if(l-diff*((c-s-e)*2+s+e)>=0) dp[i][c][s][e][l] += dp[i-1][c][s][e][l-diff*((c-s-e)*2+s+e)]
* ((c-s-e)*2+s+e) % mod, dp[i][c][s][e][l]%=mod;
if(l-diff*((c-1-s-e)*2+s+e)>=0) dp[i][c][s][e][l] += dp[i-1][c-1][s][e][l-diff*((c-1-s-e)*2+s+e)], dp[i][c][s][e][l]%=mod;
if(s) {
if(l-diff*((c-e)*2+e)>=0)dp[i][c][s][e][l] += dp[i-1][c][0][e][l-diff*((c-e)*2+e)] * (c-e) % mod, dp[i][c][s][e][l]%=mod;
if(l-diff*((c-1-e)*2+e)>=0)dp[i][c][s][e][l] += dp[i-1][c-1][0][e][l-diff*((c-1-e)*2+e)] % mod, dp[i][c][s][e][l]%=mod;
}
if(e) {
if(l-diff*((c-s)*2+s)>=0) dp[i][c][s][e][l] += dp[i-1][c][s][0][l-diff*((c-s)*2+s)] * (c-s) % mod, dp[i][c][s][e][l]%=mod;
if(l-diff*((c-1-s)*2+s)>=0) dp[i][c][s][e][l] += dp[i-1][c-1][s][0][l-diff*((c-1-s)*2+s)] % mod, dp[i][c][s][e][l]%=mod;
}
// cerr<<i<<' '<<c<<' '<<s<<' '<<e<<' '<<l<<": "<<dp[i][c][s][e][l]<<'\n';
}
ll ans=0;
// i=n-1, c=2, s=1, e=1, l += diff * 2
// i=n-1, c=1, s=1, e=0, l += diff
// i=n-1, c=1, s=0, e=1, l += diff
FOR(l,0,L){
ll diff=A[n]-A[n-1];
if(l-diff*2>=0) ans+=dp[n-1][2][1][1][l-diff*2],ans%=mod;
if(l-diff>=0) ans+=dp[n-1][1][1][0][l-diff]+dp[n-1][1][0][1][l-diff],ans%=mod;
}
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
1152 KB |
Output is correct |
6 |
Correct |
8 ms |
1000 KB |
Output is correct |
7 |
Correct |
6 ms |
896 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
8 ms |
1024 KB |
Output is correct |
10 |
Correct |
6 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1664 KB |
Output is correct |
2 |
Correct |
7 ms |
1664 KB |
Output is correct |
3 |
Correct |
7 ms |
2048 KB |
Output is correct |
4 |
Correct |
8 ms |
1792 KB |
Output is correct |
5 |
Correct |
7 ms |
1716 KB |
Output is correct |
6 |
Correct |
7 ms |
2048 KB |
Output is correct |
7 |
Correct |
6 ms |
1792 KB |
Output is correct |
8 |
Correct |
7 ms |
2048 KB |
Output is correct |
9 |
Correct |
7 ms |
2048 KB |
Output is correct |
10 |
Correct |
7 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
1152 KB |
Output is correct |
6 |
Correct |
8 ms |
1000 KB |
Output is correct |
7 |
Correct |
6 ms |
896 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
8 ms |
1024 KB |
Output is correct |
10 |
Correct |
6 ms |
1024 KB |
Output is correct |
11 |
Correct |
7 ms |
1664 KB |
Output is correct |
12 |
Correct |
7 ms |
1664 KB |
Output is correct |
13 |
Correct |
7 ms |
2048 KB |
Output is correct |
14 |
Correct |
8 ms |
1792 KB |
Output is correct |
15 |
Correct |
7 ms |
1716 KB |
Output is correct |
16 |
Correct |
7 ms |
2048 KB |
Output is correct |
17 |
Correct |
6 ms |
1792 KB |
Output is correct |
18 |
Correct |
7 ms |
2048 KB |
Output is correct |
19 |
Correct |
7 ms |
2048 KB |
Output is correct |
20 |
Correct |
7 ms |
1792 KB |
Output is correct |
21 |
Correct |
16 ms |
10532 KB |
Output is correct |
22 |
Correct |
547 ms |
95352 KB |
Output is correct |
23 |
Correct |
682 ms |
121396 KB |
Output is correct |
24 |
Correct |
620 ms |
132840 KB |
Output is correct |
25 |
Correct |
695 ms |
120076 KB |
Output is correct |
26 |
Correct |
595 ms |
119768 KB |
Output is correct |
27 |
Correct |
270 ms |
108152 KB |
Output is correct |
28 |
Correct |
329 ms |
116728 KB |
Output is correct |
29 |
Correct |
577 ms |
146424 KB |
Output is correct |
30 |
Correct |
685 ms |
120312 KB |
Output is correct |