Submission #974574

# Submission time Handle Problem Language Result Execution time Memory
974574 2024-05-03T13:20:37 Z sofija6 Skyscraper (JOI16_skyscraper) C++14
100 / 100
135 ms 79608 KB
#include <bits/stdc++.h>
#define ll long long
#define MAXN 110
#define MAXL 1010
#define MOD 1000000007
using namespace std;
ll a[MAXN],dp[MAXN][MAXN][MAXL][3];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,l;
    cin >> n >> l;
    for (ll i=1;i<=n;i++)
        cin >> a[i];
    sort(a+1,a+1+n);
    a[n+1]=a[n];
    dp[0][0][0][0]=1;
    for (ll i=1;i<=n;i++)
    {
        for (ll j=1;j<=i;j++)
        {
            for (ll cost=0;cost<=l;cost++)
            {
                for (ll ends=0;ends<3;ends++)
                {
                    ll C=(2*j-ends)*(a[i+1]-a[i]);
                    if (C>cost)
                        continue;
                    dp[i][j][cost][ends]+=dp[i-1][j-1][cost-C][ends];
                    dp[i][j][cost][ends]%=MOD;
                    dp[i][j][cost][ends]+=dp[i-1][j][cost-C][ends]*(2*j-ends);
                    dp[i][j][cost][ends]%=MOD;
                    if (ends)
                    {
                        dp[i][j][cost][ends]+=dp[i-1][j-1][cost-C][ends-1]*(3-ends);
                        dp[i][j][cost][ends]%=MOD;
                        if (ends==1)
                            dp[i][j][cost][ends]+=dp[i-1][j][cost-C][ends-1]*2*j;
                        if (ends==2)
                        {
                            if (j==1 && i==n)
                                dp[i][j][cost][ends]+=dp[i-1][j][cost-C][ends-1];
                            else if (j>1)
                                dp[i][j][cost][ends]+=dp[i-1][j][cost-C][ends-1]*(j-1);
                        }
                        dp[i][j][cost][ends]%=MOD;
                    }
                    if (!ends)
                        dp[i][j][cost][ends]+=dp[i-1][j+1][cost-C][ends]*j*(j+1);
                    if (ends==1)
                        dp[i][j][cost][ends]+=dp[i-1][j+1][cost-C][ends]*j*j;
                    if (ends==2)
                    {
                        if (j==1 && i==n)
                            dp[i][j][cost][ends]+=dp[i-1][j+1][cost-C][ends];
                        else if (j>1)
                            dp[i][j][cost][ends]+=dp[i-1][j+1][cost-C][ends]*j*(j-1);
                    }
                    dp[i][j][cost][ends]%=MOD;
                }
            }
        }
    }
    ll ans=0;
    for (ll i=0;i<=l;i++)
        ans=(ans+dp[n][1][i][2])%MOD;
    cout << (n==1?1 : ans);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 3 ms 3420 KB Output is correct
22 Correct 103 ms 67452 KB Output is correct
23 Correct 131 ms 78900 KB Output is correct
24 Correct 119 ms 77136 KB Output is correct
25 Correct 133 ms 79608 KB Output is correct
26 Correct 119 ms 74016 KB Output is correct
27 Correct 49 ms 42324 KB Output is correct
28 Correct 64 ms 48836 KB Output is correct
29 Correct 116 ms 74580 KB Output is correct
30 Correct 135 ms 79476 KB Output is correct