CSES - Aalto Competitive Programming 2024 - wk8 - Homework C++ - Results
Submission details
Task:Counting ones
Sender:ilyas.ben
Submission time:2024-10-30 14:51:43 +0200
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.55 sdetails
#8ACCEPTED0.55 sdetails
#9ACCEPTED0.55 sdetails
#10ACCEPTED0.56 sdetails

Code

#include <iostream>
#include <sstream>
#include <vector>
#include <array>

using namespace std;

bool isPairChecked(array<long long, 2> pair, std::vector<array<long long, 2>> &results)
{
    for (const auto &storedPair : results)
    {
        if ((storedPair[0] == pair[0] && storedPair[1] == pair[1]) ||
            (storedPair[0] == pair[1] && storedPair[1] == pair[0]))
        {
            return true;
        }
    }
    return false;
}

void printPairs(const std::vector<array<long long, 2>> &results)
{
    for (const auto &pair : results)
    {
        cout << pair[0] << " " << pair[1] << endl;
    }
}

int main(int argc, char const *argv[])
{
    int n, max = 0;
    string input;
    std::vector<array<long long, 2>> results;

    // input n and the
    cin >> n;
    cin.ignore();
    getline(cin, input);

    long long numbers[n];

    // assign numbers to the numbers arrays
    istringstream stream(input);
    long long number;
    int index = 0;
    while (stream >> number && index < n)
    {
        numbers[index++] = number;
    }

    // verifying the product
   // std::vector<int[2]> resultsMemory;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int x = __builtin_popcountll(static_cast<unsigned long long>(numbers[i] * numbers[j]));
            array<long long, 2> pair = {numbers[i], numbers[j]};

            if (x > max)
            {
                results.clear();
                max = x;
            }

            if (x == max)
            {
                if (!isPairChecked(pair, results))
                {
                    results.push_back(pair);
                }
            }
        }
    }
    cout << max << endl;
    printPairs(results);

    return 0;
}

/* std::cout << n << " ";
cout << numbers[17658]; */

// soit je cree un vector des couples déjà visités
// soit je verifie avec le vecteur déjà crée

Test details

Test 1

Verdict: ACCEPTED

input
5
42 100 73 94 1 

correct output
9
42 73

user output
9
42 73

Test 2

Verdict: ACCEPTED

input
5
44 19 3 94 55 

correct output
8
19 94

user output
8
19 94

Test 3

Verdict: ACCEPTED

input
10
551 71 709 840 291 122 511 570...

correct output
15
893 438

user output
15
893 438

Test 4

Verdict: ACCEPTED

input
10
968 901 548 173 973 856 715 61...

correct output
14
715 698

user output
14
715 698

Test 5

Verdict: ACCEPTED

input
100
221994 55181 870733 831328 206...

correct output
29
396737 649459

user output
29
396737 649459
14581 368163

Test 6

Verdict: ACCEPTED

input
100
892861 947477 331980 209407 82...

correct output
29
825210 578859

user output
29
825210 578859

Test 7

Verdict: ACCEPTED

input
10000
76308292 227339075 779918796 3...

correct output
50
978548139 589096701

user output
50
978548139 589096701

Test 8

Verdict: ACCEPTED

input
10000
873429404 968540665 239439572 ...

correct output
49
661547021 435157931

user output
49
661547021 435157931
868036638 911826533
581248045 964645111
898300039 959334793
...

Test 9

Verdict: ACCEPTED

input
10000
10374159 364461027 501874596 4...

correct output
50
313852607 889662850

user output
50
313852607 889662850

Test 10

Verdict: ACCEPTED

input
10000
771320644 298761159 20751947 4...

correct output
49
516789275 257079921

user output
49
516789275 257079921
859358377 964279935