#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > dp[105][55][5];
long long a[105], n, m, ans, mod=1e9+7;
void f(long long x, long long y, long long z)
{
for (pair<long long, long long> p:dp[x][y][z])
{
dp[x+1][y+1][z].push_back({p.first+(a[x+1]-a[x])*((y+1)*2+z), p.second});
dp[x+1][y][z+1].push_back({p.first+(a[x+1]-a[x])*(y*2+z+1), p.second});
if (y || z)
dp[x+1][y][z].push_back({p.first+(a[x+1]-a[x])*(y*2+z), p.second*(y*2+z)%mod});
if (y && z)
dp[x+1][y-1][z].push_back({p.first+(a[x+1]-a[x])*((y-1)*2+z), p.second*y%mod*z%mod});
if (y)
dp[x+1][y-1][z+1].push_back({p.first+(a[x+1]-a[x])*(y*2+z-1), p.second*y%mod});
if (y>=2)
dp[x+1][y-1][z].push_back({p.first+(a[x+1]-a[x])*((y-1)*2+z), p.second*y%mod*(y-1)%mod});
}
}
void g(long long x, long long y, long long z)
{
sort(dp[x][y][z].begin(), dp[x][y][z].end());
vector<pair<long long, long long> > tmp;
long long sum=0;
for (long long i=0; i<dp[x][y][z].size(); i++)
{
sum=(sum+dp[x][y][z][i].second)%mod;
if (i==(long long)dp[x][y][z].size()-1 || dp[x][y][z][i].first<dp[x][y][z][i+1].first)
{
if (dp[x][y][z][i].first<=m)
tmp.push_back({dp[x][y][z][i].first, sum});
sum=0;
}
}
dp[x][y][z]=tmp;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
if (n==1)
{
cout << 1;
return 0;
}
for (long long i=1; i<=n; i++)
cin >> a[i];
sort(a+1, a+n+1);
dp[1][0][0].push_back({0, 1});
f(1, 0, 0);
for (long long i=2; i<n; i++)
{
for (long long j=0; j<=50; j++)
{
for (long long k=0; k<=2; k++)
{
g(i, j, k);
f(i, j, k);
}
}
}
g(n, 0, 1);
g(n, 0, 2);
for (long long i=0; i<dp[n][0][1].size(); i++)
ans=(ans+dp[n][0][1][i].second)%mod;
for (long long i=0; i<dp[n][0][2].size(); i++)
ans=(ans+dp[n][0][2][i].second)%mod;
cout << ans*2%mod;
}
Compilation message
skyscraper.cpp: In function 'void g(long long int, long long int, long long int)':
skyscraper.cpp:26:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (long long i=0; i<dp[x][y][z].size(); i++)
| ~^~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:67:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (long long i=0; i<dp[n][0][1].size(); i++)
| ~^~~~~~~~~~~~~~~~~~~
skyscraper.cpp:69:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (long long i=0; i<dp[n][0][2].size(); i++)
| ~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1136 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1136 KB |
Output is correct |
4 |
Correct |
1 ms |
1112 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
2 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1372 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1136 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1136 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1136 KB |
Output is correct |
14 |
Correct |
1 ms |
1112 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1372 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
2 ms |
1372 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
2 ms |
1372 KB |
Output is correct |
22 |
Correct |
524 ms |
166624 KB |
Output is correct |
23 |
Correct |
106 ms |
36356 KB |
Output is correct |
24 |
Correct |
176 ms |
61848 KB |
Output is correct |
25 |
Correct |
127 ms |
44628 KB |
Output is correct |
26 |
Correct |
111 ms |
39536 KB |
Output is correct |
27 |
Correct |
104 ms |
39008 KB |
Output is correct |
28 |
Correct |
147 ms |
55376 KB |
Output is correct |
29 |
Correct |
269 ms |
94288 KB |
Output is correct |
30 |
Correct |
132 ms |
43608 KB |
Output is correct |