Submission #938828

# Submission time Handle Problem Language Result Execution time Memory
938828 2024-03-05T15:42:29 Z Hanksburger Skyscraper (JOI16_skyscraper) C++17
15 / 100
16 ms 7516 KB
#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

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
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1628 KB Output is correct
2 Correct 12 ms 6236 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 13 ms 6524 KB Output is correct
5 Correct 16 ms 7516 KB Output is correct
6 Correct 8 ms 4688 KB Output is correct
7 Correct 6 ms 3164 KB Output is correct
8 Correct 4 ms 2396 KB Output is correct
9 Correct 3 ms 2396 KB Output is correct
10 Correct 10 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -