//1L1YA
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define Pb push_back
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(),x.end()
#define al(x,n) x+1,x+n+1
#define SZ(x) ((int)x.size())
#define lc (id<<1)
#define rc (lc|1)
#define mid (l+r>>1)
#define dokme(x) cout << x << endl, exit(0)
#define sik(x) cout << x << endl;continue;
#define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll oo=1e18;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=111;
const int M=1011;
const int lg=23;
ll n,m,a[N],dp[M][N][3],DP[M][N][3];
int main(){
FastIO
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> a[i];
if(n==1) dokme(1);
sort(al(a,n));
DP[0][0][0]=1;
a[n+1]=1e5;
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++)
for(int k=1;k<=i;k++)
for(int c=0;c<3;c++){
int p=2*k-c,w=j-p*(a[i+1]-a[i]);
dp[j][k][c]=0;
if(w<0) continue;
dp[j][k][c]=(DP[w][k-1][c]*(k-c)+DP[w][k][c]*p+DP[w][k+1][c]*k)%mod;
if(c) dp[j][k][c]=(dp[j][k][c]+DP[w][k-1][c-1]*(3-c)+DP[w][k][c-1]*(3-c))%mod;
}
for(int j=0;j<=m;j++)
for(int k=0;k<=i;k++)
for(int c=0;c<3;c++)
DP[j][k][c]=dp[j][k][c];
}
ll ans=0;
for(int i=0;i<=m;i++) ans=(ans+dp[i][1][2])%mod;
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
0 ms |
1116 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
0 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
0 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
0 ms |
1116 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
0 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
1112 KB |
Output is correct |
16 |
Correct |
0 ms |
860 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
0 ms |
860 KB |
Output is correct |
21 |
Correct |
1 ms |
684 KB |
Output is correct |
22 |
Correct |
44 ms |
4956 KB |
Output is correct |
23 |
Correct |
63 ms |
5468 KB |
Output is correct |
24 |
Correct |
52 ms |
4696 KB |
Output is correct |
25 |
Correct |
62 ms |
5636 KB |
Output is correct |
26 |
Correct |
58 ms |
4700 KB |
Output is correct |
27 |
Correct |
17 ms |
1628 KB |
Output is correct |
28 |
Correct |
22 ms |
1884 KB |
Output is correct |
29 |
Correct |
46 ms |
3444 KB |
Output is correct |
30 |
Correct |
63 ms |
5476 KB |
Output is correct |