CSES - Aalto Competitive Programming 2024 - wk8 - Homework C++ - Results
Submission details
Task:Counting ones
Sender:hungdojan
Submission time:2024-10-24 21:28:53 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.28 sdetails
#80.28 sdetails
#90.28 sdetails
#100.28 sdetails

Code

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

#define I_2D(row, col, width) ((row) * (width) + (col))
#define PRINT_ARR(arr, n)                                                      \
  do {                                                                         \
    for (int i = 0; i < n; i++) {                                              \
      cout << arr[i] << " ";                                                   \
    }                                                                          \
    cout << "\n";                                                              \
  } while (0)
#define PRINT_VEC_ARR(v, n)                                                    \
  do {                                                                         \
    for (int i = 0; i < n; i++) {                                              \
      cout << i << ": ";                                                       \
      for (auto item : v[i]) {                                                 \
        cout << item << " ";                                                   \
      }                                                                        \
      cout << endl;                                                            \
    }                                                                          \
  } while (0)

typedef long long ll;

ll get_ones(ll i) {
  ll count = 0;
  for (; i; i >>= 1) {
    if (i & 1)
      count++;
  }
  return count;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  ll arr[n];

  int fi = 0, si = 0;
  ll max_ones = 0;

  ll ones;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    for (int j = 0; j < i; j++) {
      ones = bitset<sizeof(ll)>(arr[i] * arr[j]).count();
      if (ones > max_ones) {
        fi = i;
        si = j;
        max_ones = ones;
      }

    }
  }

  cout << max_ones << endl;
  cout << arr[fi] << " " << arr[si] << endl;
  return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
5
42 100 73 94 1 

correct output
9
42 73

user output
6
73 42

Test 2

Verdict: ACCEPTED

input
5
44 19 3 94 55 

correct output
8
19 94

user output
6
94 19

Test 3

Verdict:

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

correct output
15
893 438

user output
7
291 709

Test 4

Verdict:

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

correct output
14
715 698

user output
6
715 901

Test 5

Verdict:

input
100
221994 55181 870733 831328 206...

correct output
29
396737 649459

user output
8
204155 870733

Test 6

Verdict:

input
100
892861 947477 331980 209407 82...

correct output
29
825210 578859

user output
8
735883 530397

Test 7

Verdict:

input
10000
76308292 227339075 779918796 3...

correct output
50
978548139 589096701

user output
8
448825797 790763507

Test 8

Verdict:

input
10000
873429404 968540665 239439572 ...

correct output
49
661547021 435157931

user output
8
764160129 513627775

Test 9

Verdict:

input
10000
10374159 364461027 501874596 4...

correct output
50
313852607 889662850

user output
8
166776351 138613281

Test 10

Verdict:

input
10000
771320644 298761159 20751947 4...

correct output
49
516789275 257079921

user output
8
611943337 88339815