Submission #938829

# Submission time Handle Problem Language Result Execution time Memory
938829 2024-03-05T15:44:07 Z Hanksburger Skyscraper (JOI16_skyscraper) C++17
20 / 100
1714 ms 524288 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;
    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);
            }
        }
    }
    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:65: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]
   65 |     for (long long i=0; i<dp[n][0][1].size(); i++)
      |                         ~^~~~~~~~~~~~~~~~~~~
skyscraper.cpp:68: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]
   68 |     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 1112 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 2 ms 1644 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1880 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 6488 KB Output is correct
5 Correct 15 ms 7516 KB Output is correct
6 Correct 9 ms 4528 KB Output is correct
7 Correct 6 ms 3164 KB Output is correct
8 Correct 3 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 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 2 ms 1644 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 2 ms 1880 KB Output is correct
12 Correct 12 ms 6236 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 13 ms 6488 KB Output is correct
15 Correct 15 ms 7516 KB Output is correct
16 Correct 9 ms 4528 KB Output is correct
17 Correct 6 ms 3164 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 3 ms 2396 KB Output is correct
20 Correct 10 ms 5468 KB Output is correct
21 Correct 211 ms 76116 KB Output is correct
22 Runtime error 1714 ms 524288 KB Execution killed with signal 9
23 Halted 0 ms 0 KB -