QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#528914#6760. 合并书本Qwerty1232#80 960ms6076kbC++237.8kb2024-08-24 02:52:532024-08-24 02:52:54

Judging History

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

  • [2024-08-24 02:52:54]
  • 评测
  • 测评结果:80
  • 用时:960ms
  • 内存:6076kb
  • [2024-08-24 02:52:53]
  • 提交

answer

#include <iostream>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

constexpr int N = 105;
constexpr int LG = 41;

int64_t shit[10];

std::vector<std::pair<std::string, int64_t>> dp[N][LG];

std::mt19937 rnd;
void clear_vec(int s, std::vector<std::pair<std::string, int64_t>>& vec) {
    std::sort(vec.begin(), vec.end());

    std::list<std::remove_reference_t<decltype(vec[0])>> list;
    for (auto& s : vec) {
        list.emplace_front(std::move(s.first), s.second);
    }
    // list.reverse();
    // for (int k : std::array{2}) {
    //     for (auto it = list.begin(); it != list.end(); it++) {
    //         int dlt = 0;
    //         for (auto it2 = std::next(it); dlt < k && it2 != list.end(); it2++) {
    //             if (it->second <= it2->second) {
    //                 dlt++;
    //                 bool fk = true;

    //                 int sz = std::min(it->first.size(), it2->first.size());
    //                 for (int t = 0, sm1 = 0, sm2 = 0; t < sz; t++) {
    //                     sm1 += it->first[t];
    //                     sm2 += it2->first[t];
    //                     fk &= sm1 >= sm2;
    //                 }
    //                 if (fk) {
    //                     shit[k != 2]++;

    //                     it2--;
    //                     dlt--;
    //                     list.erase(std::next(it2));
    //                 }
    //             }
    //         }
    //     }
    // }
    for (int k : std::array{2}) {
        for (auto it = list.begin(); it != list.end(); it++) {
            int dlt = 0;
            for (auto it2 = std::next(it); dlt < k && it2 != list.end(); it2++) {
                if (it->second <= it2->second) {
                    dlt++;
                    bool fk = true;

                    int sz = std::min(it->first.size(), it2->first.size());
                    for (int t = 0, sm1 = 0, sm2 = 0; t < sz; t++) {
                        sm1 += it->first[t];
                        sm2 += it2->first[t];
                        fk &= sm1 >= sm2;
                    }
                    if (fk) {
                        shit[k != 2]++;

                        it2--;
                        dlt--;
                        list.erase(std::next(it2));
                    }
                }
            }
        }
    }
    vec.assign(list.begin(), list.end());
    vec.shrink_to_fit();
}

void clear_vec1(int s, std::vector<std::pair<std::string, int64_t>>& vec) {
    std::sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end(), [&](const auto& a, const auto& b) { return a.first == b.first; }), vec.end());

    int cnt = 0;
    for (int i = 0; i < vec.size(); i++) {
        for (int j = i + 1; j < vec.size(); j++) {
            if (vec[i].second <= vec[j].second) {
                bool fk = true;
                for (int t = 0; t < s; t++) {
                    fk &= vec[i].first[t] <= vec[j].first[t];
                }
                if (fk) {
                    vec.erase(vec.begin() + j);
                    j--;
                    cnt++;
                }
            }
        }
    }
    vec.shrink_to_fit();
    if (cnt > 100 || vec.size() > 100) {
        // std::cerr << "cleared: " << cnt << "  " << vec.size() << "\n";
    }
}

void clear_vec2(int s, const std::vector<std::pair<std::string, int64_t>>& vec0, std::vector<std::pair<std::string, int64_t>>& vec) {
    int cnt = 0;

    for (int i = 0; i < vec0.size(); i++) {
        for (int j = 0; j < vec.size(); j++) {
            if (vec0[i].second <= vec[j].second) {
                bool fk = true;
                for (int t = 0; t < s; t++) {
                    fk &= vec0[i].first[t] <= vec[j].first[t];
                }
                if (fk) {
                    vec.erase(vec.begin() + j);
                    j--;
                    cnt++;
                }
            }
        }
    }
    vec.shrink_to_fit();
    if (cnt > 0) {
        std::cerr << "cleared_fuck: " << cnt << "\n";
    }
}

int32_t main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n = 0;

    int t;
    std::cin >> t;
    std::vector<std::vector<int>> inputs(t);
    for (auto& vec : inputs) {
        int k;
        std::cin >> k;
        vec.resize(k);
        for (auto& i : vec) {
            std::cin >> i;
        }
        n = std::max(n, k);
    }

    dp[1][0] = {{std::string(1, 1), 0}};
    for (int s = 2; s <= n; s++) {
        std::vector<int> ord(s - 1);
        std::iota(ord.begin(), ord.end(), 1);
        std::sort(ord.begin(), ord.end(), [&](int a, int b) { return abs(a - s / 2) < abs(b - s / 2); });

        for (int k = 0; k < LG; k++) {
            static std::unordered_map<std::string, int64_t> map;
            // static __gnu_pbds::cc_hash_table<std::string, int64_t> map;
            map.clear();

            for (int k1 = 0; k1 < LG; k1++) {
                for (int k2 = 0; k2 < LG; k2++) {
                    if (k != std::max(k1, k2) + 1) {
                        continue;
                    }
                    for (int s1 : ord) {
                        int s2 = s - s1;
                        if (dp[s1][k1].empty() || dp[s2][k2].empty()) {
                            continue;
                        }
                        if (k >= LG) {
                            continue;
                        }

                        for (auto [v1, c1] : dp[s1][k1]) {
                            for (auto [v2, c2] : dp[s2][k2]) {
                                v2.resize(std::max(v2.size(), v1.size() + 1));
                                for (int i = 0; i < v1.size(); i++) {
                                    v2[i + 1] += v1[i];
                                }
                                int64_t cost = c1 + c2 + ((1LL << k1) - 1) + ((1LL << k2) - 1);
                                // dp[s][k].push_back({all, cost});
                                auto [it, suc] = map.insert({v2, cost});
                                if (!suc) {
                                    it->second = std::min(it->second, cost);
                                }
                            }
                        }
                    }
                }
            }
            auto& vec = dp[s][k];
            vec.assign(map.begin(), map.end());
            clear_vec(s, dp[s][k]);
        }

        {
            int i = s;
            std::cerr << i << "  ";
            // std::cerr << i << "   ";
            // for (int j = 0; j < LG; j++) {
            //     std::cerr << dp[i][j].size() << " \n"[j == LG - 1];
            // }
            std::cerr.flush();
        }
    }

    int64_t total_sum = 0;
    for (int i = 1; i <= n; i++) {
        // std::cerr << i << "   ";
        for (int j = 0; j < LG; j++) {
            // std::cerr << dp[i][j].size() << " \n"[j == LG - 1];
            total_sum += dp[i][j].size();
        }
    }
    std::cerr << "total: " << total_sum << std::endl;
    std::cerr << shit[0] << " " << shit[1] << "\n";

    for (auto& vec : inputs) {
        int m = vec.size();
        int64_t ans = 1e18;
        std::sort(vec.begin(), vec.end());
        for (int k = 0; k < LG; k++) {
            for (auto [vc2, ct] : dp[m][k]) {
                std::vector<char> vc;
                for (int i = 0; i < vc2.size(); i++) {
                    vc.insert(vc.end(), vc2[i], i);
                }
                int64_t res = 0;
                res += ct;
                for (int i = 0; i < m; i++) {
                    res += vec.rbegin()[i] * int64_t(vc[i]);
                }
                ans = std::min(ans, res);
            }
        }
        std::cout << ans << "\n";
    }

    return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 2ms
memory: 3616kb

input:

10
7
1123 49789157 413323654 2706564 2927094 150 118615
7
3 129759848 804638078 3 13679143 570776857 654029932
1
1
6
1 1 1 2 2 2
3
999999810 999999043 999999202
7
1 2 3 49763 3691 3569835 2925
4
327658691 806170222 346679860 346383249
1
1
4
1 1 1 2
6
1 1 1 1 1 1

output:

55542760
1368245805
0
15
1999998246
56400
1020721804
0
6
13

result:

ok 10 numbers

Test #2:

score: 5
Accepted
time: 2ms
memory: 3684kb

input:

10
7
213 268 63 7 967 7 22052029
7
1 265923976 472789929 1 1 470475169 343368258
7
1 19 372 7196 138949 2682695 51794746
7
1 1 1 2 2 2 4
7
999999794 999999919 999999066 999999842 999999196 999999936 999999842
7
10867 146096 93 1 1 280230 29430
7
162066046 918510621 451526315 118693343 70646597 22247...

output:

1552
1079767418
2829260
21
5999997716
186503
1536786988
91
22
18

result:

ok 10 numbers

Test #3:

score: 5
Accepted
time: 2ms
memory: 3860kb

input:

10
11
241989 3 881273 3451 4 139032 5 6543 2812483 1546680 9
11
3 573103223 275326913 106433034 871434747 631247004 690166797 3 212836284 570933697 259491409
11
1 6 43 284 1873 12328 81113 533669 3511191 23101297 151991108
11
1 1 1 2 2 2 4 4 4 8 8
11
999999796 999999778 999999561 999999989 999999731...

output:

2819071
3319538622
27241978
60
9999996533
42813068
2559262097
1580
70
102

result:

ok 10 numbers

Test #4:

score: 5
Accepted
time: 3ms
memory: 3692kb

input:

10
13
836 412717524 401028726 26811 13866 887 355 27 51742476 849 145 23497644 245739
13
1 340278685 667310626 777981413 644221578 797415065 415910260 791888781 57470166 430855032 305196231 39774837 177199623
13
1 4 24 119 587 2894 14251 70170 345510 1701254 8376776 41246263 203091762
13
1 1 1 2 2 2...

output:

476559393
4648089271
51758252
93
11999995678
90501411
6259327649
6821
119
102

result:

ok 10 numbers

Test #5:

score: 5
Accepted
time: 6ms
memory: 3708kb

input:

10
22
776 24 978555 130 69929 308 82236 107902 133781 85 1005152 352998 30828907 11052 97523363 916153873 436 936615 23 400 55 174
16
3 423761758 899451343 376607666 3 139145680 906709010 802975514 664857002 780444615 777185992 744647598 405531571 3 765617301 38995584
15
1 3 15 63 251 999 3981 15848...

output:

132037358
6819225728
84262019
214
21002085382
206823885
6595035278
130641
1064
3901

result:

ok 10 numbers

Test #6:

score: 5
Accepted
time: 6ms
memory: 3776kb

input:

10
22
1055 431267 4116 50 77816 676985197 179 7 233469 319 3 402101 775746370 1273815 37106291 67770 159 142577182 85244425 2521002 23 187
18
1 645691791 448180634 63038102 602497356 717242329 1 688453392 234138571 1 272075583 146167832 560503312 277845554 105055101 30775956 903105974 212483311
18
1...

output:

946932507
5004165202
146249995
257
18000253459
628772840
9219151506
1206139
832
3901

result:

ok 10 numbers

Test #7:

score: 5
Accepted
time: 6ms
memory: 3744kb

input:

10
28
37971032 354908055 461677774 844292 1 298294554 26 6723520 444122859 134313571 65562 2 20 619194 919547 198 364523 339 19 1084924 170223 399183 1 19625846 389429 30 32692572 5265886
25
3 248045587 963407548 323796573 42641957 500892988 662629593 15629907 588720039 282703914 344522615 369907884...

output:

1338972670
9018178260
307511604
732
19000515182
1397234690
7949255779
49200037
2865
1800

result:

ok 10 numbers

Test #8:

score: 5
Accepted
time: 9ms
memory: 3772kb

input:

10
28
428655 2332 3366 12542 7148 113 818539 4 18 473825 157286 91836 170801385 124 342109 17959 257905 127 5703 884 471111 430 1 211 42656 3 326273 4355
27
1 85526477 762041910 39158143 799122900 243430975 497801265 553830240 243795921 156062773 671204985 690564761 384519093 15454567 794964818 2307...

output:

3491381
8765561828
338172160
2025
25033542420
825537382
11598461949
49200037
4723
1800

result:

ok 10 numbers

Test #9:

score: 5
Accepted
time: 53ms
memory: 3992kb

input:

10
47
20768082 25 32345092 1747363 397249281 28 3075 11609 3 6 45429517 4427 16041 1 65026496 150911 3875 2662 23270 46208197 21 4137 12 5027312 48775344 28 36 7788097 145556840 406 104 7572 811256189 354 145526632 101998772 4247314 10160 1973 40 1 11894 1753 8 40042507 86100 717633542
32
3 38159934...

output:

1826031648
12760765397
760869113
1064
35073724503
150381767
21890757718
9957735657
4723
1800

result:

ok 10 numbers

Test #10:

score: 5
Accepted
time: 49ms
memory: 4048kb

input:

10
48
250209506 67327 1594742 12 44195 4 1255759 353945 106 68706412 24140006 7971 8041441 500777589 434 332883887 255442 4052 3695190 122270082 6123937 201957 1423 108081 244 422 2760852 42154 177 74 8 4 208457 66 51446 505 203 22 835 1582706 145 5103 17265 7341 14 221644600 4729 934
6
1 614810765 ...

output:

1046790625
2279177775
997789888
310
11999998107
1553893920
10379255077
1580
129191
1800

result:

ok 10 numbers

Test #11:

score: 5
Accepted
time: 69ms
memory: 4104kb

input:

10
50
147603372 275 2 28042 21553581 289155959 150 2219693 28 8 236 17 171291 17 16136 36017490 270548 2265939 3 4788491 483162984 319890 4509445 791 96599 237 166266592 92401768 613664454 10455478 338525 19741 5305658 2245604 727719496 5955 9 1908 4839 16225 13744 28992258 273 244549 10686 47617 85...

output:

1914223852
14329484685
799465794
72781
47073717749
2243986038
29678027842
17976180477
608537
691798

result:

ok 10 numbers

Test #12:

score: 5
Accepted
time: 66ms
memory: 4408kb

input:

10
50
21476 56307367 6089 187662 1 25407 8447 921225369 268 154412972 2292968 840 219410540 52760816 12118 723314265 7309 6727197 1444 2078045 539 16 87 4981106 36 669602 823 7475396 3353 5238167 1521 283 405 494423322 350990102 4475136 3 28383582 172898666 626 222 2648 1 29 286387137 1578 25379 167...

output:

2977766867
18728788847
1120436351
178263
65073705454
2222498562
24053854427
17976180477
608537
691798

result:

ok 10 numbers

Test #13:

score: 5
Accepted
time: 65ms
memory: 4100kb

input:

10
50
226 47701 572547730 245 285 29862003 466 1397985 20241 5020651 124 8372876 232036 2913 63756236 5 8173200 319484731 30 1561 78332699 65778 254056 15 24945 821826 4790 4 5570 495 16150 74131646 168605322 902321 15477509 7584151 27123 32672 1956828 2121755 1737 9 27097 21 25115 119587330 1563311...

output:

1064626842
22179329896
1079289625
178263
57073709156
629177007
21925481613
19996838517
216322
691798

result:

ok 10 numbers

Test #14:

score: 5
Accepted
time: 173ms
memory: 4496kb

input:

10
60
3486066 91 370245 96 47 2 3735 1045256 300190 60121949 337721 26754300 2511771 2 27584943 3968960 125 6572 83282301 430 79556638 3139814 29 82402 79499189 2181225 24974 197505 48 71584886 220747 8 482 23019442 282 43703 1353746 54 13 13795352 47783755 619 341228816 36630535 4 1930 2953652 7381...

output:

786329490
26024966081
1457893441
1106027
85073688750
1348795414
37011722883
2744
8197332
6948

result:

ok 10 numbers

Test #15:

score: 5
Accepted
time: 426ms
memory: 5296kb

input:

10
70
2937 8 9363276 39944045 71289789 245232 13788 192772 151 4846346 59569185 5 52600 61838 21939 825147 98 14769 126399 966474 58545 66558 27 36263453 50 90426783 6010741 95 397008995 1 155488 2820748 1820399 6544165 35414 576 10 441889 227994 42892479 7 7 157 49526 1431339 270 609857813 12021658...

output:

1345847342
42105249959
2030012212
21495952
101073678565
4350936425
38699808747
52987017552
2744
6948

result:

ok 10 numbers

Test #16:

score: 5
Accepted
time: 960ms
memory: 6076kb

input:

10
80
287909659 15 2906 813 9572 23265 369492293 69437663 36865 75236 6 1042 6 29 35 4943 29 2708913 733 190725903 12 17361 11 2 7502649 790785 201132446 18 206727894 7 18387169 263 4095376 47231 12 143 31704 10236 1392706 1659 63 4386955 272613 8368244 392808 6409410 3157598 7624 9 19 1091705 25385...

output:

2247991104
48887888608
2484773802
136315044
115073677371
2735203629
45877988579
60987017564
536943117
67169

result:

ok 10 numbers

Test #17:

score: 0
Time Limit Exceeded

input:

10
99
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
63
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:


result:


Test #18:

score: 0
Time Limit Exceeded

input:

10
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
95
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:


result:


Test #19:

score: 0
Time Limit Exceeded

input:

10
99
20960812 219576969 12706 3531080 5 13347 4257 770876154 6720 7 15070300 95492959 114149 4271305 1001 84 9938 259098 5 3201 343162411 29534 25376 30083 53 605922 1 350508840 18741 22 2866 7964760 40008972 10 11744 27196 408 1415 3555868 3449928 101007 3018610 26793 356 183775 12 95159 682246113...

output:


result:


Test #20:

score: 0
Time Limit Exceeded

input:

10
100
1049 78473423 637 136611 5569464 1622 3 1 9822897 8 4856 11 237784166 111931094 42308394 389667 8607 44 29 23 16788859 51 726 19 1 441286 336488761 1752 603 2 27832 4 2416121 19279999 420496571 24116733 917152413 1704799 329 48140124 10230 8 1137 18 17 190254279 203508 2 126058833 806948059 5...

output:


result: