답안 #737094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737094 2023-05-06T15:41:22 Z danikoynov Skyscraper (JOI16_skyscraper) C++14
100 / 100
151 ms 122188 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 110, maxl = 1e3 + 10;
const ll mod = 1e9 + 7;
int n, l, a[maxn];

void add(ll &cell, ll val)
{
    val %= mod;
    cell += val;
    if (cell >= mod)
        cell -= mod;
}

ll dp[maxn][maxl][maxn][3];
void solve()
{
    cin >> n >> l;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];

    sort(a + 1, a + n + 1);
    a[n + 1] = a[n];
    if (n == 1)
    {
        cout << 1 << endl;
        return;
    }

    if (n == 2)
    {
        if (a[2] - a[1] <= l)
        {
            cout << 2 << endl;
        }
        else
        {
            cout << 0 << endl;
        }
        return;
    }

    dp[1][2 * (a[2] - a[1])][1][0] = 1;
    dp[1][a[2] - a[1]][1][1] = 1;
    ///cout << a[1] << " " << a[2] << endl;
    for (int i = 1; i < n; i ++)
    {
        for (int j = 0; j <= l; j ++)
        {
            for (int k = 0; k <= n; k ++)
            {
                for (int p = 0; p < 3; p ++)
                {
                    if (dp[i][j][k][p] == 0)
                        continue;
                    ///cout << i << " " << j << " " << k << " " << p << " " << dp[i][j][k][p] << endl;
                    int new_diff = j + (k * 2 - p + 2) * (a[i + 2] - a[i + 1]); /// add a new component
                    ///cout << new_diff << endl;
                    if (new_diff <= l)
                        add(dp[i + 1][new_diff][k + 1][p], dp[i][j][k][p] * (ll)(k + 1 - p));
                    new_diff = j + (k * 2 - p) * (a[i + 2] - a[i + 1]); /// add to an existing component
                    ///cout << new_diff << endl;
                    if (new_diff <= l)
                        add(dp[i + 1][new_diff][k][p], dp[i][j][k][p] * (ll)((k * 2 - p)));
                    if (p != 2)
                    {
                        new_diff = j + (k * 2 - p - 1) * (a[i + 2] - a[i + 1]);

                        if (new_diff <= l)
                            add(dp[i + 1][new_diff][k][p + 1], dp[i][j][k][p]);

                        new_diff = j + (k * 2 - p + 1) * (a[i + 2] - a[i + 1]);

                        if (new_diff <= l)
                            add(dp[i + 1][new_diff][k + 1][p + 1], dp[i][j][k][p]);
                    }
                    new_diff = j + (k * 2 - p - 2) * (a[i + 2] - a[i + 1]);
                    //cout << i << " " << j << " " << k << " " << p << " " << dp[i][j][k][p] << endl;
                      //  cout << new_diff << endl;
                    if (new_diff <= l && k > 1)
                        add(dp[i + 1][new_diff][k - 1][p], dp[i][j][k][p] * (k - 1));
                }
            }
        }
    }

    ll ans = 0;
    for (int s = 0; s <= l; s ++)
    {
        ans = ans + dp[n][s][1][2];
        ///cout << s << " :: " << dp[n][s][1][2] << endl;
        if (ans >= mod)
        ans -= mod;
    }
    cout << (ans * 2)% mod << endl;

}

int main()
{
    solve();
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 3 ms 816 KB Output is correct
6 Correct 3 ms 1876 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 1080 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 2 ms 2104 KB Output is correct
3 Correct 2 ms 1328 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 1332 KB Output is correct
9 Correct 2 ms 1876 KB Output is correct
10 Correct 2 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 3 ms 816 KB Output is correct
6 Correct 3 ms 1876 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 1080 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 2 ms 2104 KB Output is correct
13 Correct 2 ms 1328 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 2 ms 2260 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 1332 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 2 ms 2388 KB Output is correct
22 Correct 129 ms 122188 KB Output is correct
23 Correct 151 ms 105548 KB Output is correct
24 Correct 139 ms 115488 KB Output is correct
25 Correct 141 ms 117316 KB Output is correct
26 Correct 124 ms 101232 KB Output is correct
27 Correct 48 ms 45712 KB Output is correct
28 Correct 59 ms 57908 KB Output is correct
29 Correct 115 ms 107748 KB Output is correct
30 Correct 138 ms 117828 KB Output is correct