CSES - HIIT Open 2024 - Results
Submission details
Task:Inheritance
Sender:Barren plateau
Submission time:2024-11-16 15:58:16 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED1.04 sdetails
#2ACCEPTED1.11 sdetails
#3ACCEPTED1.01 sdetails
#4ACCEPTED1.22 sdetails
#5ACCEPTED2.49 sdetails
#6ACCEPTED2.49 sdetails
#72.50 sdetails
#82.50 sdetails
#9ACCEPTED2.49 sdetails
#10ACCEPTED2.49 sdetails
#11ACCEPTED2.50 sdetails
#12ACCEPTED1.96 sdetails
#13ACCEPTED1.94 sdetails
#14ACCEPTED1.92 sdetails
#15ACCEPTED2.50 sdetails
#16ACCEPTED2.49 sdetails
#17ACCEPTED2.49 sdetails
#18ACCEPTED2.49 sdetails
#19ACCEPTED2.50 sdetails
#20ACCEPTED2.49 sdetails
#21ACCEPTED2.50 sdetails
#22ACCEPTED2.50 sdetails
#23ACCEPTED2.49 sdetails
#24ACCEPTED2.49 sdetails
#25ACCEPTED2.51 sdetails
#26ACCEPTED2.50 sdetails
#27ACCEPTED2.49 sdetails
#28ACCEPTED2.49 sdetails

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];
    }

    mt19937 rng(13423562572);

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

    vector<pair<Z, Z>> X;
    for(Z it = 0; it < 10000000; ++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];
            } else {
                diff -= V[i];
            }
        }
        if(diff < 0) {
            diff = -diff;
            mask = bound & ~mask;
        }
        X.push_back({diff, mask});
    }

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

    for(Z i = 1; i < (Z)X.size(); ++i) {
        if(X[i - 1].first == X[i].first) {
            Z mask1 = X[i - 1].second;
            Z mask2 = X[i].second;
            Z a = mask1 & ~mask2;
            Z b = mask2 & ~mask1;
            if(a && b) {
                for(Z i = 0; i < n; ++i) {
                    if(a & (Z{1} << i)) {
                        cout << V[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: ACCEPTED

input
2
1 1

correct output
1
1

user output


Test 2

Verdict: ACCEPTED

input
3
1 2 3

correct output
3
1 2

user output

1 2 

Test 3

Verdict: ACCEPTED

input
3
2 2 2

correct output
2
2

user output


Test 4

Verdict: ACCEPTED

input
6
3 2 5 1 7 8

correct output
2 1
3

user output
3 2 

Test 5

Verdict: ACCEPTED

input
40
27487790693 27487790692 274877...

correct output
27487790651 27487774282
27487790652 27487774281

user output
27487790690 27487790686 274877...

Test 6

Verdict: ACCEPTED

input
40
27487790693 27487790692 274877...

correct output
27487790688 27487790486 274877...

user output
27487790674 27487790637 274877...

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)

Error:
terminate called after throwing an instance of 'int'

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)

Error:
terminate called after throwing an instance of 'int'

Test 9

Verdict: ACCEPTED

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

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

user output
15 2047 65535 131071 262143 33...

Test 10

Verdict: ACCEPTED

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

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

user output
5242880 83886080 1342177280 53...

Test 11

Verdict: ACCEPTED

input
40
642081522561 67331511756 17915...

correct output
10000000008 10000000005
10000000007 10000000006

user output
10000000029 10000000012 100000...

Test 12

Verdict: ACCEPTED

input
40
27487790739 27487790734 274877...

correct output
27487790739 27487790701 274877...

user output
27487790737 27487790702 274877...

Test 13

Verdict: ACCEPTED

input
40
27487790726 27487790723 274877...

correct output
27487790681 27487790678
27487790680 27487790679

user output
27487790726 27487790748 274877...

Test 14

Verdict: ACCEPTED

input
40
27487790744 27487790715 274877...

correct output
27487790711 27487790710 274877...

user output
27487790710 27487790706 274877...

Test 15

Verdict: ACCEPTED

input
40
19669566523 16528665765 196239...

correct output
16528665765 10929136447 125755...

user output
19669566523 19623932705 125755...

Test 16

Verdict: ACCEPTED

input
40
18103769567 14444217460 183355...

correct output
15982577206 17769110557 124644...

user output
15982577206 16010998271 124644...

Test 17

Verdict: ACCEPTED

input
40
17856614174 19048069863 175427...

correct output
17563061793 16010946154 132865...

user output
17563061793 16754109846 184478...

Test 18

Verdict: ACCEPTED

input
40
1786812 2068856 1749503 168298...

correct output
2068856 2090472 1725454 169431...

user output
1786812 1984383 1735504 159945...

Test 19

Verdict: ACCEPTED

input
40
1129650 1662217 1678779 182047...

correct output
1820473 1456513 1939701 160831...

user output
1820473 2027113 1660276 140085...

Test 20

Verdict: ACCEPTED

input
40
24808689091 27070970684 226856...

correct output
22685667072 25049152240 183404...

user output
20249742938 15146917475 166598...

Test 21

Verdict: ACCEPTED

input
40
16712721711 16122645964 169234...

correct output
25590302248 25776083681 200636...

user output
16923456895 19004163920 245811...

Test 22

Verdict: ACCEPTED

input
40
27016877723 26624688594 255882...

correct output
18637668548 14215273154 231053...

user output
27005623777 18191692253 259950...

Test 23

Verdict: ACCEPTED

input
40
22612801338 17987950258 220495...

correct output
22612801338 28914153399 201796...

user output
22612801338 22049531790 178789...

Test 24

Verdict: ACCEPTED

input
40
23397776706 18089114838 194902...

correct output
17041900579 24486781810 275051...

user output
23592548295 17041900579 244867...

Test 25

Verdict: ACCEPTED

input
40
24840659504 32664220268 190864...

correct output
32664220268 19086427470 240084...

user output
24840659504 19086427470 170438...

Test 26

Verdict: ACCEPTED

input
40
22577006557 25490929450 308237...

correct output
22577006557 33714917325 183357...

user output
35494095564 25493455844 297389...

Test 27

Verdict: ACCEPTED

input
40
25196082534 25787578777 336717...

correct output
20236894598 25724569573 318791...

user output
33671758794 20236894598 196695...

Test 28

Verdict: ACCEPTED

input
40
5000000000 5000000001 50000000...

correct output
5000000002 5000000594 50000022...

user output
5000000001 5000000004 50000000...