CSES - Aalto Competitive Programming 2024 - wk8 - Homework C++ - Results
Submission details
Task:Counting ones
Sender:snude
Submission time:2024-10-27 11:52:52 +0200
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#30.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#60.00 sdetails
#70.21 sdetails
#80.22 sdetails
#90.22 sdetails
#100.21 sdetails

Compiler report

input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:64:67: warning: 'second' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |         printf("%lld %lld\n", input_line[first], input_line[second]);
      |                                                                   ^
input/code.cpp:64:47: warning: 'first' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |         printf("%lld %lld\n", input_line[first], input_line[second]);
      |                                               ^

Code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

// Debug printing
#ifdef DEBUG
#define deb(fmt, args...) printf("DEBUG: %d: " fmt, __LINE__, ##args)
#else
#define deb(fmt, args...)
#endif

void print_array(vector<int> in, const string title = "Vector")
{
	cout << title << " [\n";
	for (const auto &el : in) {
		cout << el << " ";
	}
	cout << "\n] END\n";
}

void print_matrix(vector<vector<int> > in, const string title = "Matrix")
{
	cout << title << "[\n";
	for (unsigned int i = 0; i < in.size(); i++) {
		for (unsigned int j = 0; j < in[i].size(); j++) {
			cout << in[i][j] << " ";
		}
		cout << "\n";
	}
	cout << "] END\n";
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	// Read the input parameters
	int n;
	cin >> n;

	// Read values from one line
	vector<ll> input_line(n);
	// ll tmp;
	for (int i = 0; i < n; i++) {
		cin >> input_line[i];
		// cin >> tmp;
	}

	ll max = 0L;
	int first, second;
	for (unsigned int i = 0; i < input_line.size() - 1; i++) {
		for (unsigned int j = i + 1; j < input_line.size() - 1; j++) {
			int pop_count = __builtin_popcount(input_line[i] * input_line[j]);
			if (pop_count > max) {
				first = i;
				second = j;
				max = pop_count;
			}
		}
	}
	printf("%lld\n", max);
	printf("%lld %lld\n", input_line[first], input_line[second]);

	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:

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

correct output
15
893 438

user output
13
291 893

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
28
14581 368163

Test 6

Verdict:

input
100
892861 947477 331980 209407 82...

correct output
29
825210 578859

user output
24
724329 990225

Test 7

Verdict:

input
10000
76308292 227339075 779918796 3...

correct output
50
978548139 589096701

user output
30
596018291 381828933

Test 8

Verdict:

input
10000
873429404 968540665 239439572 ...

correct output
49
661547021 435157931

user output
30
701341503 612237185

Test 9

Verdict:

input
10000
10374159 364461027 501874596 4...

correct output
50
313852607 889662850

user output
30
823836911 256366065

Test 10

Verdict:

input
10000
771320644 298761159 20751947 4...

correct output
49
516789275 257079921

user output
30
50663103 518491267