This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > dp[105][55][5];
long long a[105], 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]*2, p.second});
dp[x+1][y][z+1].push_back({p.first-a[x], p.second});
if (y || z)
dp[x+1][y][z].push_back({p.first, p.second*(y*2+z)%mod});
if (y && z)
dp[x+1][y-1][z].push_back({p.first+a[x]*2, p.second*y%mod*z%mod});
if (y)
dp[x+1][y-1][z+1].push_back({p.first+a[x], p.second*y%mod});
if (y>=2)
dp[x+1][y-1][z].push_back({p.first+a[x]*2, 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==dp[x][y][z].size()-1 || dp[x][y][z][i].first<dp[x][y][z][i+1].first)
{
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);
long long n, m, ans=0;
cin >> n >> m;
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);
}
}
}
for (long long i=0; i<dp[n][0][1].size(); i++)
if (dp[n][0][1][i].first<=m-a[n])
ans=(ans+dp[n][0][1][i].second)%mod;
for (long long i=0; i<dp[n][0][2].size(); i++)
if (dp[n][0][2][i].first<=m-a[n]*2)
ans=(ans+dp[n][0][2][i].second)%mod;
cout << (ans*2)%mod;
}
Compilation message (stderr)
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:29:14: 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]
29 | if (i==dp[x][y][z].size()-1 || dp[x][y][z][i].first<dp[x][y][z][i+1].first)
| ~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:60: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]
60 | for (long long i=0; i<dp[n][0][1].size(); i++)
| ~^~~~~~~~~~~~~~~~~~~
skyscraper.cpp:63: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]
63 | for (long long i=0; i<dp[n][0][2].size(); i++)
| ~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |