#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> bool chkmax(T&x,T y){return x<y?x=y,1:0;}
template<typename T> bool chkmin(T&x,T y){return x>y?x=y,1:0;}
const int md=1e9+7;
int n,l,a[105],dp[105][1005][3],tmp[105][1005][3];
void chkadd(int&x,int y){x+=y; if(x>=md) x-=md;}
int mul(int x,int y){return (ll)x*y%md;}
int main(){
scanf("%d%d",&n,&l);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
if(n==1){printf("1"); return 0;}
sort(a+1,a+n+1);
if((a[2]-a[1])*2<=l) dp[1][(a[2]-a[1])*2][0]=1;
if(a[2]-a[1]<=l) dp[1][a[2]-a[1]][1]=2;
for(int i=2;i<=n;i++){
int d=a[i+1]-a[i];
for(int j=1;j<=n;j++)
for(int s=0;s<=l;s++)
for(int k=0;k<=2;k++)
tmp[j][s][k]=dp[j][s][k],dp[j][s][k]=0;
for(int j=1;j<=n;j++){
for(int s=0;s<=l;s++){
for(int k=0;k<=2;k++){
int v=tmp[j][s][k];
//dodajem bez spajanja, nema novih krajeva
int ns=s+d*(2*j-k);
if(ns>=0&&ns<=l) chkadd(dp[j][ns][k],mul(v,2*j-k));
//spajam, nema novih krajeva
ns=s+d*(2*j-k-2);
if(ns>=0&&j>1&&ns<=l) chkadd(dp[j-1][ns][k],mul(v,j-1));
//pravim novu komponentu, nema novih krajeva
ns=s+d*(2*j-k+2);
if(ns>=0&&j<n&&ns<=l) chkadd(dp[j+1][ns][k],mul(v,j+1-k));
//dodajem bez spajanja, ima novi kraj
ns=s+d*(2*j-k-1);
if(ns>=0&&k<2&&ns<=l) chkadd(dp[j][ns][k+1],mul(v,2-k));
//pravim novu komponentu, ima novi kraj
ns=s+d*(2*j-k+1);
if(ns>=0&&k<2&&ns<=l) chkadd(dp[j+1][ns][k+1],mul(v,2-k));
}
}
}
}
int ans=0;
for(int i=0;i<=l;i++) chkadd(ans,dp[1][i][2]);
printf("%d",ans);
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d%d",&n,&l);
| ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:26:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | for(int i=1;i<=n;i++) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
440 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
416 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
440 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
440 KB |
Output is correct |
21 |
Correct |
3 ms |
568 KB |
Output is correct |
22 |
Correct |
216 ms |
2156 KB |
Output is correct |
23 |
Correct |
306 ms |
2676 KB |
Output is correct |
24 |
Correct |
252 ms |
2660 KB |
Output is correct |
25 |
Correct |
285 ms |
2668 KB |
Output is correct |
26 |
Correct |
259 ms |
2768 KB |
Output is correct |
27 |
Correct |
88 ms |
1660 KB |
Output is correct |
28 |
Correct |
110 ms |
1796 KB |
Output is correct |
29 |
Correct |
226 ms |
2356 KB |
Output is correct |
30 |
Correct |
289 ms |
2764 KB |
Output is correct |