#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void ngha();
const int mod2=1e9+7;
const int mod1=998244353;
struct ib
{
int a;
int b;
};
struct icd
{
int a,b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e;
};
int n,m,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
// fin(task),fou(task);
//#endif
NHP
//modwwe
// cin>>res;
ngha(),down
checktime
}
int dp[101][101][1001][4];
int a[101];
void ngha()
{
cin>>n>>k;
for(int i=1; i<=n; i++)
cin>>a[i];
dp[1][0][0][1]=1;
dp[1][0][0][0]=1;
dp[1][0][0][2]=1;
if(n==1) dp[1][0][0][3]=1;
/// 1 khoa van trai
///2 khoa van phai
///0 khong khoa
///4 khoa 2 van
sort(a+1,a+1+n);
for(int i=1; i<n; i++)
{
s2=a[i+1]-a[i];
for(int j=0; j<n; j++)
{
for(int z=0; z<=k; z++)
{ // if(i==1) cout<<j<<" "<<z,down
for(int t=0; t<=3; t++){
// if(i==1)
// cout<<j<<" "<<z<<" "<<t<<" "<<dp[i][j][z][t],down
if(dp[i][j][z][t]==0) continue;
if(t==0)/// khong khoa van
{
s3=s2*(2+2*j)+z;
if(s3<=k){
dp[i+1][j][s3][0]=(dp[i+1][j][s3][0]+dp[i][j][z][0]*(j+1)*2)%mod2;
dp[i+1][j-1][s3][0]=(dp[i+1][j-1][s3][0]+dp[i][j][z][0]*j)%mod2;
dp[i+1][j+1][s3][0]=(dp[i+1][j+1][s3][0]+dp[i][j][z][0]*(j+2))%mod2;
/// chuyen ve 0 cac buoc khac tuong tu thoi :)))
dp[i+1][j][s3][1]=(dp[i+1][j][s3][1]+dp[i][j][z][0])%mod2;
dp[i+1][j+1][s3][1]=(dp[i+1][j+1][s3][1]+dp[i][j][z][0])%mod2;
dp[i+1][j][s3][2]=(dp[i+1][j][s3][2]+dp[i][j][z][0])%mod2;
dp[i+1][j+1][s3][2]=(dp[i+1][j+1][s3][2]+dp[i][j][z][0])%mod2;}
}
if(t==1)
{
s3=s2*(1+2*j)+z;
if(s3<=k){
dp[i+1][j][s3][1]=(dp[i+1][j][s3][1]+dp[i][j][z][1]*(2*j+1))%mod2;
dp[i+1][j-1][s3][1]=(dp[i+1][j-1][s3][1]+dp[i][j][z][1]*j)%mod2;
dp[i+1][j+1][s3][1]=(dp[i+1][j+1][s3][1]+dp[i][j][z][1]*(j+1))%mod2;
/// giu nguyen
dp[i+1][j][s3][3]=(dp[i+1][j][s3][3]+dp[i][j][z][1])%mod2;
dp[i+1][j+1][s3][3]=(dp[i+1][j+1][s3][3]+dp[i][j][z][1])%mod2;
}
//if(i==1) cout<<dp[2][j+1][s3][3]<<" "<<s3<<" "<<dp[i][j][z][1],down
}
if(t==2)
{
s3=s2*(1+2*j)+z;
if(s3<=k){
dp[i+1][j][s3][2]=(dp[i+1][j][s3][2]+dp[i][j][z][2]*(2*j+1))%mod2;
dp[i+1][j-1][s3][2]=(dp[i+1][j-1][s3][2]+dp[i][j][z][2]*j)%mod2;
dp[i+1][j+1][s3][2]=(dp[i+1][j+1][s3][2]+dp[i][j][z][2]*(j+1))%mod2;
///giu nguyen
dp[i+1][j][s3][3]=(dp[i+1][j][s3][3]+dp[i][j][z][2])%mod2;
dp[i+1][j+1][s3][3]=(dp[i+1][j+1][s3][3]+dp[i][j][z][2])%mod2;
}
}
if(t==3)
{
s3=s2*2*j+z;
if(s3<=k){
dp[i+1][j][s3][3]=(dp[i+1][j][s3][3]+dp[i][j][z][3]*(2*j))%mod2;
dp[i+1][j-1][s3][3]=(dp[i+1][j-1][s3][3]+dp[i][j][z][3]*j)%mod2;
dp[i+1][j+1][s3][3]=(dp[i+1][j+1][s3][3]+dp[i][j][z][3]*j)%mod2;
}
}
}
}
}
}
s2=0;
for(int i=0; i<=k; i++)
{
s2+=dp[n][0][i][3];
s2=s2%mod2;
}
cout<<s2;
///1 2 3
/**1 0 0 1
2 1 1 3
3 2 3 3
4 1 7 3
5 0 9 3
example: 1 5 3 4 2 =>(5-1)+(5-3)+(4-3)+(4-2)=9
*/
}
Compilation message
skyscraper.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2904 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2772 KB |
Output is correct |
11 |
Correct |
1 ms |
2904 KB |
Output is correct |
12 |
Correct |
1 ms |
2904 KB |
Output is correct |
13 |
Correct |
1 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2908 KB |
Output is correct |
20 |
Correct |
1 ms |
2908 KB |
Output is correct |
21 |
Correct |
2 ms |
3676 KB |
Output is correct |
22 |
Correct |
47 ms |
35284 KB |
Output is correct |
23 |
Correct |
43 ms |
15108 KB |
Output is correct |
24 |
Correct |
39 ms |
20308 KB |
Output is correct |
25 |
Correct |
48 ms |
16976 KB |
Output is correct |
26 |
Correct |
38 ms |
15696 KB |
Output is correct |
27 |
Correct |
23 ms |
14936 KB |
Output is correct |
28 |
Correct |
22 ms |
18136 KB |
Output is correct |
29 |
Correct |
49 ms |
25704 KB |
Output is correct |
30 |
Correct |
44 ms |
17164 KB |
Output is correct |