QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290829#7793. 雷同Cyanmond20 2ms4308kbC++204.5kb2023-12-25 17:00:142023-12-25 17:00:15

Judging History

你现在查看的是最新测评结果

  • [2023-12-25 17:00:15]
  • 评测
  • 测评结果:20
  • 用时:2ms
  • 内存:4308kb
  • [2023-12-25 17:00:14]
  • 提交

answer

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tag_and_trait.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// namespace gt = __gnu_pbds;
#define IS_MULTITEST 1

using namespace std;

// #include "angel/math/modint.hpp"

#pragma region Macros
// clang-format off
using ll = long long; using uint = unsigned int; using ull = unsigned long long;
using i32 = int; using i64 = ll; using u32 = uint; using u64 = ull;
using i128 = __int128_t; using u128 = __uint128_t;
using Str = string;
template <class T> using Vec = vector<T>;
template <class T> using RevPriq = priority_queue<T, vector<T>, greater<T>>;
constexpr std::array<std::pair<int, int>, 4> dxy4 = {{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}};
constexpr std::array<std::pair<int, int>, 8> dxy8 = {
    {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}}};
constexpr int inf32 = 1 << 30; constexpr ll inf64 = 1ll << 60;
constexpr char eoln = '\n';
#define L(i, l, r) for (int i = (l); i < (r); ++i)
#define R(i, l, r) for (int i = (r) - 1; i >= (l); --i)
#define ALL(x) (x).begin(), (x).end()
#define mem(a, x) memset((a), (x), sizeof(a))
#define sz(a) (int)((a).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
// clang-format on
#pragma endregion

// Coding Space

constexpr int B = 30;
int N;
Vec<ll> W, sW;
Vec<Vec<Vec<ll>>> dp;
Vec<Vec<Vec<ll>>> fldp;
Vec<Vec<Vec<int>>> lp, rp;

ll hcost(ll n) {
    if (n <= 60) return (1ll << n) - 1;
    else return inf64;
}

ll wSum(int l, int r) {
    return sW[r] - sW[l];
}

void work() {
    L(h, 0, N) {
        L(width, 0, N) {
            L(l, 0, N) {
                int r = l + width;
                if (r >= N) continue;
                if (h == 0) {
                    if (l == r) dp[l][r][h] = 0;
                    else dp[l][r][h] = inf64;
                } else if (l == r) {
                    dp[l][r][h] = inf64;
                } else if (h > r - l) {
                    dp[l][r][h] = inf64;
                } else {
                    ll xv = numeric_limits<ll>::max();
                    ll yv = xv;
                    int li = lp[l][r - 1][h] == -1 ? l : lp[l][r - 1][h];
                    int ri = lp[l + 1][r][h] == -1 ? r - 1 : lp[l + 1][r][h];
                    L(m, li, ri + 1) {
                        if (m == r) break;
                        ll ac = wSum(l, m + 1) + wSum(m + 1, r + 1) + hcost(h - 1);
                        ll lv = dp[l][m][h - 1];
                        ll rv = fldp[m + 1][r][h - 1];
                        if (xv > lv + rv + ac) {
                            xv = lv + rv + ac;
                            lp[l][r][h] = m;
                        }
                    }

                    li = rp[l][r - 1][h] == -1 ? l : rp[l][r - 1][h];
                    ri = rp[l + 1][r][h] == -1 ? r - 1 : rp[l + 1][r][h];
                    L(m, li, ri + 1) {
                        if (m == r) break;
                        ll ac = wSum(l, m + 1) + wSum(m + 1, r + 1) + hcost(h - 1);
                        ll lv = fldp[l][m][h - 1];
                        ll rv = dp[m + 1][r][h - 1];
                        if (yv > lv + rv + ac) {
                            yv = lv + rv + ac;
                            rp[l][r][h] = m;
                        }
                    }
                    dp[l][r][h] = min(xv, yv);
                }

                fldp[l][r][h] = min(fldp[l][r][h], dp[l][r][h]);
                if (h != 0) {
                    fldp[l][r][h] = min(fldp[l][r][h], fldp[l][r][h - 1] - hcost(h) + hcost(h - 1));
                }
            }
        }
    }
}

void main_() {
    cin >> N;
    W.assign(N, 0);
    for (auto &e : W) cin >> e;

    sort(ALL(W));
    sW.assign(N + 1, 0);
    L(i, 0, N) sW[i + 1] = sW[i] + W[i];

    dp.resize(N);
    lp.resize(N);
    L(i, 0, N) {
        dp[i].resize(N);
        lp[i].resize(N);
        L(j, 0, N) {
            dp[i][j].assign(N, inf64);
            lp[i][j].resize(N, -1);
        }
    }
    fldp = dp;
    rp = lp;
    ll ans = inf64;
    work();
    L(i, 0, N) {
        ans = min(ans, dp[0][N - 1][i]);
    }

    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if constexpr (IS_MULTITEST == 0) {
        main_();
    } else {
        // multitest (cf-style)
        int T;
        cin >> T;
        while (T--) {
            main_();
            cout << flush;
        }
    }
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 3624kb

input:

4
6
1 3 5 7 9 11
6
2 4 6 8 10 12
6
100 1000 100 10 100 10
2
114514 1919810

output:

86
103
1981
2034324

result:

ok 4 tokens

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 15
Accepted
time: 1ms
memory: 3608kb

input:

5
12
2 4 3 2 2 3 4 2 3 2 2 1
12
3 3 3 2 3 2 3 2 1 1 2 4
12
6 2 2 2 5 4 6 1 2 8 8 6
12
1 4 2 2 1 6 7 2 4 1 7 5
12
11 1 2 6 16 16 15 8 8 16 6 12

output:

114
109
183
146
400

result:

ok 5 tokens

Test #3:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

5
12
4 2 4 3 2 4 4 4 3 1 1 1
12
3 4 6 5 2 3 2 5 1 3 4 4
12
3 6 4 3 5 2 5 2 5 2 3 1
12
1 2 2 3 7 7 6 4 1 2 9 3
12
12 5 12 4 3 9 3 14 5 11 6 6

output:

120
154
150
162
316

result:

ok 5 tokens

Test #4:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

5
12
3 1 2 1 2 3 1 1 1 2 1 3
12
4 7 7 6 6 2 3 7 1 7 6 6
12
13 7 13 7 9 1 5 13 3 13 9 7
12
12 12 15 13 15 22 33 33 21 9 15 3
12
123141171 193440418 455041175 665153544 746164805 372591232 659412139 493891488 760749047 4896558 90497398 964891156

output:

80
223
349
708
18084123310

result:

ok 5 tokens

Test #5:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

5
12
2 4 3 2 5 1 6 2 5 2 1 4
12
2 6 6 6 12 8 8 6 12 6 10 11
12
23 26 26 31 13 20 13 31 2 1 15 30
12
56 33 66 31 27 64 26 2 48 55 46 66
12
113216 35921 62630 73720 41172 102245 41642 39101 40760 105980 2857 63443

output:

133
335
782
1809
2470930

result:

ok 5 tokens

Subtask #3:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #6:

score: 0
Wrong Answer
time: 2ms
memory: 4308kb

input:

5
30
34 3 20 7 6 9 22 3 24 2 3 40 25 9 6 4 3 36 5 38 21 9 5 4 21 6 28 32 17 3
30
1 6 9 2 6 9 7 2 2 4 3 5 6 8 9 7 2 7 12 7 8 4 9 8 2 8 2 12 3 2
30
4 1 1 4 4 1 3 4 3 2 4 4 1 1 2 3 3 3 2 1 2 4 4 3 3 4 4 4 3 1
30
9 6 9 8 3 10 10 1 6 1 1 6 6 10 4 9 1 4 1 6 1 10 4 9 10 7 5 2 9 8
28
7 9 6 3 5 5 1 10 9 3 1 ...

output:

2020
846
434
854
680

result:

wrong answer 1st words differ - expected: '2019', found: '2020'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #39:

score: 0
Time Limit Exceeded

input:

2
2500
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #5:

0%