CSES - HIIT Open 2024 - Results
Submission details
Task:Inheritance
Sender:Barren plateau
Submission time:2024-11-16 16:57:16 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#11.19 sdetails
#21.19 sdetails
#31.39 sdetails
#41.48 sdetails
#5--details
#6--details
#71.19 sdetails
#81.29 sdetails
#9--details
#10--details
#11--details
#12--details
#13--details
#14--details
#15--details
#16--details
#17--details
#18--details
#19--details
#20--details
#21--details
#22--details
#23--details
#24--details
#25--details
#26--details
#27--details
#28--details

Code

#include <bits/stdc++.h>
using namespace std;

using Z = long long int;

Z n;
vector<Z> V;

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

    cin >> n;
    V.resize(n);
    for(Z i = 0; i < n; ++i) {
        cin >> V[i];
    }

    std::sort(V.rbegin(), V.rend());

    // ebin hack
    Z asd = 0;
    while(asd < n && V[n - 1 - asd] == (Z{1} << asd)) {
        ++asd;
    }

    n -= asd;
    V.resize(n);

    mt19937 rng(13423562572);

    Z bound = (Z{1} << n) - 1;

    vector<pair<Z, Z>> X;
    for(Z it = 0; it < 20000000; ++it) {
        Z mask = (Z)(uniform_int_distribution<uint64_t>()(rng) & (uint64_t)bound);
        Z diff = 0;
        for(Z i = 0; i < n; ++i) {
            if(mask & (Z{1} << i)) {
                diff += V[i];
            }
        }
        X.push_back({diff, mask});
    }

    sort(X.begin(), X.end(), [&](const pair<Z, Z>& a, const pair<Z, Z>& b) { return a.first < b.first; });

    Z slack = (Z{1} << asd) - 1;

    for(Z i = 1; i < (Z)X.size(); ++i) {
        Z diff = X[i].first - X[i - 1].first;
        if(diff <= slack) {
            Z mask1 = X[i - 1].second;
            Z mask2 = X[i].second;
            Z a = mask1 & ~mask2;
            Z b = mask2 & ~mask1;
            if((a || diff) && b) {
                for(Z i = 0; i < n; ++i) {
                    if(a & (Z{1} << i)) {
                        cout << V[i] << " ";
                    }
                }
                for(Z i = 0; i < asd; ++i) {
                    if(diff & (Z{1} << i)) {
                        cout << (Z{1} << i) << " ";
                    }
                }
                cout << "\n";
                for(Z i = 0; i < n; ++i) {
                    if(b & (Z{1} << i)) {
                        cout << V[i] << " ";
                    }
                }
                cout << "\n";
                return 0;
            }
        }
    }
    throw 5;

    return 0;
}

Test details

Test 1

Verdict:

input
2
1 1

correct output
1
1

user output
(empty)

Test 2

Verdict:

input
3
1 2 3

correct output
3
1 2

user output
(empty)

Test 3

Verdict:

input
3
2 2 2

correct output
2
2

user output
(empty)

Test 4

Verdict:

input
6
3 2 5 1 7 8

correct output
2 1
3

user output
(empty)

Test 5

Verdict:

input
40
27487790693 27487790692 274877...

correct output
27487790651 27487774282
27487790652 27487774281

user output
(empty)

Test 6

Verdict:

input
40
27487790693 27487790692 274877...

correct output
27487790688 27487790486 274877...

user output
(empty)

Test 7

Verdict:

input
40
1 2 4 8 16 32 64 128 256 512 1...

correct output
549755813887
1 2 4 8 16 32 64 128 256 512 1...

user output
(empty)

Test 8

Verdict:

input
40
1 2 4 8 16 32 64 128 256 512 1...

correct output
274877906943
1 2 4 8 16 32 64 128 256 512 1...

user output
(empty)

Test 9

Verdict:

input
40
1 3 7 15 31 63 127 255 511 102...

correct output
1 7 31 2047 4095 68719476735 2...

user output
(empty)

Test 10

Verdict:

input
40
1 3 5 10 20 40 80 160 320 640 ...

correct output
5 40 80 640 1280 10240 20480 1...

user output
(empty)

Test 11

Verdict:

input
40
642081522561 67331511756 17915...

correct output
10000000008 10000000005
10000000007 10000000006

user output
(empty)

Test 12

Verdict:

input
40
27487790739 27487790734 274877...

correct output
27487790739 27487790701 274877...

user output
(empty)

Test 13

Verdict:

input
40
27487790726 27487790723 274877...

correct output
27487790681 27487790678
27487790680 27487790679

user output
(empty)

Test 14

Verdict:

input
40
27487790744 27487790715 274877...

correct output
27487790711 27487790710 274877...

user output
(empty)

Test 15

Verdict:

input
40
19669566523 16528665765 196239...

correct output
16528665765 10929136447 125755...

user output
(empty)

Test 16

Verdict:

input
40
18103769567 14444217460 183355...

correct output
15982577206 17769110557 124644...

user output
(empty)

Test 17

Verdict:

input
40
17856614174 19048069863 175427...

correct output
17563061793 16010946154 132865...

user output
(empty)

Test 18

Verdict:

input
40
1786812 2068856 1749503 168298...

correct output
2068856 2090472 1725454 169431...

user output
(empty)

Test 19

Verdict:

input
40
1129650 1662217 1678779 182047...

correct output
1820473 1456513 1939701 160831...

user output
(empty)

Test 20

Verdict:

input
40
24808689091 27070970684 226856...

correct output
22685667072 25049152240 183404...

user output
(empty)

Test 21

Verdict:

input
40
16712721711 16122645964 169234...

correct output
25590302248 25776083681 200636...

user output
(empty)

Test 22

Verdict:

input
40
27016877723 26624688594 255882...

correct output
18637668548 14215273154 231053...

user output
(empty)

Test 23

Verdict:

input
40
22612801338 17987950258 220495...

correct output
22612801338 28914153399 201796...

user output
(empty)

Test 24

Verdict:

input
40
23397776706 18089114838 194902...

correct output
17041900579 24486781810 275051...

user output
(empty)

Test 25

Verdict:

input
40
24840659504 32664220268 190864...

correct output
32664220268 19086427470 240084...

user output
(empty)

Test 26

Verdict:

input
40
22577006557 25490929450 308237...

correct output
22577006557 33714917325 183357...

user output
(empty)

Test 27

Verdict:

input
40
25196082534 25787578777 336717...

correct output
20236894598 25724569573 318791...

user output
(empty)

Test 28

Verdict:

input
40
5000000000 5000000001 50000000...

correct output
5000000002 5000000594 50000022...

user output
(empty)