CSES - Aalto Competitive Programming 2024 - wk8 - Homework C++ - Results
Submission details
Task:Counting ones
Sender:MallocManfred
Submission time:2024-10-24 01:21:10 +0300
Language:C++ (C++11)
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.64 sdetails
#8ACCEPTED0.64 sdetails
#9ACCEPTED0.64 sdetails
#10ACCEPTED0.64 sdetails

Code

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define vout(x) for(int i=0;i<(long long)x.size();i++) printf("%lld ",x[i]);
#define REP(i,a,b) for (int i = a; i < b; i++)

// g++ <filename>.cpp -g -Wall -Wextra -DDEBUG -o <executable>

// copied from: https://codeforces.com/blog/entry/79024
// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

signed main() {
    
    int n;
    cin >> n;
    vector<int> numbers(n);
    
    REP(i, 0, n) {
        cin >> numbers[i];
    }

    sort(numbers.begin(), numbers.end());

    int max_ones = 0;   
    int num1 = 0;
    int num2 = 0;
    
    REP(i, 0, n) {
        REP(j, 0, n) {
            
            if (i == j) continue;

            int prod = numbers[i] * numbers[j];
            int ones_count = __builtin_popcountll(prod);
            
            if (ones_count > max_ones) {
                max_ones = ones_count;
                num1 = numbers[i];
                num2 = numbers[j];
            }
        }
    }
    
    cout << max_ones << "\n";
    cout << num1 << " " << num2 << "\n";
    
    return 0;
}

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
438 893

Test 4

Verdict: ACCEPTED

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

correct output
14
715 698

user output
14
698 715

Test 5

Verdict: ACCEPTED

input
100
221994 55181 870733 831328 206...

correct output
29
396737 649459

user output
29
14581 368163

Test 6

Verdict: ACCEPTED

input
100
892861 947477 331980 209407 82...

correct output
29
825210 578859

user output
29
578859 825210

Test 7

Verdict: ACCEPTED

input
10000
76308292 227339075 779918796 3...

correct output
50
978548139 589096701

user output
50
589096701 978548139

Test 8

Verdict: ACCEPTED

input
10000
873429404 968540665 239439572 ...

correct output
49
661547021 435157931

user output
49
370248567 973097170

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
257079921 516789275