#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
using i64 =long long;
const int mod=1e9+7;
const int inf=1e9;
const int N=100;
const int L=1'000;
int dp[2][N+2][L+1][3];
//nr de vecini liberi
void add_self(int& x,int y)
{
x+=y;
x%=mod;
}
int add(int x,int y)
{
return (x+y)%mod;
}
int prod(int x,int y)
{
return (1LL*x*y)%mod;
}
main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,l;
cin>>n>>l;
if(n==1)
{
cout<<1;
return 0;
}
vector<int>a(n);
for(auto &c:a)
{
cin>>c;
}
sort(all(a));
a.pb(10000);
dp[1][0][0][0]=1;
for(int i=0;i<n;i++)
{
for(int j=1;j<=i+1;j++)
{
for(int cost=0;cost<=l;cost++)
{
for(int m=0;m<=2;m++)
{
int& rez=dp[i&1][j][cost][m];
rez=0;
int old_cost=cost-(2*j-m)*(a[i+1]-a[i]);
if(old_cost<0)
{
continue;
}
//unim 2 comp
add_self(rez , prod((j+1-m)*j, dp[(i&1)^1][j+1][old_cost][m]));
if(i==n-1 && m==2 && j==1)
{
add_self(rez , dp[(i&1)^1][j+1][old_cost][m]);
}
//adaugam la un capat unei comp
//e capat
if(m>0)
{
if(m==1)add_self(rez , prod(2*j , dp[(i&1)^1][j][old_cost][m-1]));
else if(m==2 && j==1 && i==n-1)add_self(rez , prod(1 , dp[(i&1)^1][j][old_cost][m-1]));
else add_self(rez , prod(j-1 , dp[(i&1)^1][j][old_cost][m-1]));
}
add_self(rez , prod(2*j-m , dp[(i&1)^1][j][old_cost][m]));
//adaugam o noua componenta
add_self(rez , dp[(i&1)^1][j-1][old_cost][m]);
if(m>0)
{
add_self(rez , prod(3-m , dp[(i&1)^1][j-1][old_cost][m-1]));
}
}
}
}
dp[1][0][0][0]=0;
}
int rez=0;
for(int i=0;i<=l;i++)
{
add_self(rez , dp[(n&1)^1][1][i][2]);
}
cout<<rez;
}
Compilation message
skyscraper.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
476 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
476 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
124 ms |
2048 KB |
Output is correct |
23 |
Correct |
149 ms |
2640 KB |
Output is correct |
24 |
Correct |
126 ms |
2592 KB |
Output is correct |
25 |
Correct |
140 ms |
2640 KB |
Output is correct |
26 |
Correct |
121 ms |
2736 KB |
Output is correct |
27 |
Correct |
48 ms |
1752 KB |
Output is correct |
28 |
Correct |
61 ms |
1872 KB |
Output is correct |
29 |
Correct |
115 ms |
2388 KB |
Output is correct |
30 |
Correct |
143 ms |
2600 KB |
Output is correct |