답안 #483426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483426 2021-10-29T11:58:15 Z prvocislo Skyscraper (JOI16_skyscraper) C++17
100 / 100
57 ms 15136 KB
/*░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░░░░░░░░░
░░██░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░░░░░
░░██████░░░░░░░░░░░░░░████░░░░██░░░░░░░░░░░░░░░░░░░░░░░░
░░██████████░░░░░░░░████░░░░  ██░░░░░░░░░░░░░░░░░░░░░░░░
░░██░░░░██████████████░░░░    ██░░░░░░░░░░░░░░░░░░░░░░░░
░░██░░  ░░░░░░░░░░░░░░░░░░    ██░░░░░░░░░░░░░░░░░░░░░░░░
░░██░░    ░░░░░░░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░░░░░
░░██░░    ░░░░░░░░░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░░░
░░░░██  ░░░░░░░░░░░░░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░
░░░░██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░░░░░░░░░░░░░░░░░
░░░░██░░░░░░░░░░░░░░░░░░░░  ████░░░░████▓▓▓▓▓▓██░░░░░░░░
░░██░░░░░░  ████░░░░░░░░░░████████░░██░░░░░░░░░░██░░░░░░
░░██░░░░░░████████░░░░░░░░████  ██░░██░░░░░░░░░░░░██░░░░
░░██░░░░░░████  ██░░░░░░░░░░████░░██░░░░░░░░░░░░░░░░██░░
░░████  ░░▒▒████▒▒░░░░░░░░░░▒▒▒▒  ██░░████████▓▓░░░░██░░
████████        ░░░░░░░░░░░░░░  ██░░████░░░░░░░░████████
██      ████        ░░░░░░░░  ██████░░░░░░░░░░░░░░░░████
██          ██████    ██████████░░░░░░░░░░░░░░░░░░░░░░██
██                ██████████░░░░░░░░░░░░░░░░░░░░░░░░░░██
██              ░░░░░░░░▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░██
██            ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██
██              ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░
▒▒▓▓    ░░░░░░  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░
░░██      ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░░░
░░░░██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░░░░░
░░░░░░████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████░░░░░░░░
░░░░░░░░░░████████████████▓▓▓▓▓▓████████████░░░░░░░░░░*/
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
typedef long long ll;
using namespace std;

const int mod = 1e9 + 7, maxn = 105, maxl = 1005;
void upd(int& a, int b) { a = (a + b) % mod; }
int mul(int a, int b) { return (a * 1ll * b) % ((ll)mod); }
int dp[maxn][maxn][maxl][3], a[maxn];
// dp[pocet cisel][pocet komponentov][momentalny sucet (a_i namiesto otaznikov][pocet koncov]
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n == 1)
    {
        cout << "1\n";
        return 0;
    }
    sort(a, a + n);
    a[n] = 10000;
    if (a[1] - a[0] <= l) dp[1][1][a[1] - a[0]][1] = 2;
    if ((a[1] - a[0]) * 2 <= l) dp[1][1][(a[1] - a[0]) * 2][0] = 1;
    for (int i = 1; i < n; i++)
    {
        int x = a[i + 1] - a[i];
        for (int cmp = 1; cmp <= i; cmp++)
        {
            for (int sum = 0; sum <= l; sum++)
            {
                for (int e = 0; e < 3; e++)
                {
                    if (!dp[i][cmp][sum][e]) continue;
                    // idem ho umiestnit na kraj
                    if (e < 3)
                    {
                        int merge_sum = sum + x * (2 * (cmp - 1) + 2 - (e + 1));
                        if (merge_sum <= l)
                        {
                            if (i == n - 1) upd(dp[i + 1][cmp][merge_sum][e + 1], dp[i][cmp][sum][e]);
                            else upd(dp[i + 1][cmp][merge_sum][e + 1], mul(dp[i][cmp][sum][e], (2 - e) * (cmp - e)));
                        }
                        int alone_sum = sum + x * (2 * cmp + 2 - (e + 1));
                        if (alone_sum <= l) upd(dp[i + 1][cmp + 1][alone_sum][e + 1], mul(dp[i][cmp][sum][e], 2 - e));
                    }
                    // idem ho dat ako novy komponent
                    int alone_sum = sum + x * (2 * cmp + 2 - e);
                    if (alone_sum <= l) upd(dp[i + 1][cmp + 1][alone_sum][e], dp[i][cmp][sum][e]);
                    // idem ho pripojit na kraj existujuceho komponentu
                    int append_sum = sum + x * (2 * (cmp - 1) + 2 - e);
                    if (append_sum <= l) upd(dp[i + 1][cmp][append_sum][e], mul(dp[i][cmp][sum][e], (2 * cmp - e)));
                    // idem spojit dva komponenty
                    int merge_sum = sum + x * (2 * (cmp - 2) + 2 - e);
                    if (merge_sum <= l && cmp >= 2)
                    {
                        if (e == 0)
                            upd(dp[i + 1][cmp - 1][merge_sum][e], mul(dp[i][cmp][sum][e], cmp * (cmp - 1)));
                        if (e == 1)
                            upd(dp[i + 1][cmp - 1][merge_sum][e], mul(dp[i][cmp][sum][e], (cmp - 1) * (cmp - 1)));
                        if (e == 2 && i == n - 1)
                            upd(dp[i + 1][cmp - 1][merge_sum][e], dp[i][cmp][sum][e]);
                        if (e == 2 && i != n - 1)
                            upd(dp[i + 1][cmp - 1][merge_sum][e], mul(dp[i][cmp][sum][e], (cmp - 1) * (cmp - 2)));
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int sum = 0; sum <= l; sum++) upd(ans, dp[n][1][sum][2]);
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 368 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 57 ms 15136 KB Output is correct
23 Correct 42 ms 5444 KB Output is correct
24 Correct 49 ms 8132 KB Output is correct
25 Correct 46 ms 6124 KB Output is correct
26 Correct 40 ms 5828 KB Output is correct
27 Correct 20 ms 7628 KB Output is correct
28 Correct 28 ms 9036 KB Output is correct
29 Correct 44 ms 11204 KB Output is correct
30 Correct 45 ms 6180 KB Output is correct