Task: | Counting ones |
Sender: | paulschulte |
Submission time: | 2024-10-23 21:02:05 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.28 s | details |
#8 | ACCEPTED | 0.28 s | details |
#9 | ACCEPTED | 0.28 s | details |
#10 | ACCEPTED | 0.28 s | details |
Code
// ~/.vim/cpp_template.cpp #include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <string> #include <limits> #define REP(i,a,b) for (int i = a; i < b; i++) // Type Aliases for 1D and 2D vectors with initialization #define vi(n, val) vector<int>(n, val) // 1D vector of ints with size n, initialized to val #define vll(n, val) vector<long long>(n, val) // 1D vector of long longs with size n, initialized to val #define ll long long #define vvi(n, m, val) vector<vector<int>>(n, vector<int>(m, val)) // 2D vector of ints (n x m), initialized to val #define vvll(n, m, val) vector<vector<long long>>(n, vector<long long>(m, val)) // 2D vector of long longs (n x m), initialized to val #define LL_INF std::numeric_limits<long long int>::max() #define INF std::numeric_limits<int>::max() using namespace std; template <typename T> void pV(const std::vector<T>& vec, const std::string& label = "Vector") { std::cout << label << ": [ "; for (const auto& elem : vec) { std::cout << elem << " "; } std::cout << "]" << std::endl; } void dfs(int s, vector<bool> *visited, vector<int> (*adj)[]) { if ((*visited)[s]) return; (*visited)[s] = true; // process node s for (auto u: (*adj)[s]) { dfs(u, visited, adj); } } /* // DEPTH-FRIRST-SEARCH vector<int> adj[N]; vector<bool> visited(N, false); int u, v; for(int i = 0; i < M;i++){ cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); } */ vector<long long> dijkstra(int N, int x, vector<vector<pair<int,int>>> *adj){ vector<bool> processed(N, false); vector<long long> distance(N, LL_INF); priority_queue<pair<long long,int>> q; //for (int i = 1; i <= n; i++) distance[i] = INF; distance[x] = 0; q.push({0,x}); while (!q.empty()) { int a = q.top().second; q.pop(); if (processed[a]) continue; processed[a] = true; for (auto u : (*adj)[a]) { int b = u.first, w = u.second; if (distance[a]+w < distance[b]) { distance[b] = distance[a]+w; q.push({-distance[b],b}); } } } return distance; } /* DIJKSTRA //vector<vector<pair<int,int>>> adj(N, vector<pair<int, int>>(N)); */ int countBits(long long x) { return __builtin_popcountll(x); } int main() { ios::sync_with_stdio(0); cin.tie(0); // Your code starts here int n; cin >> n; // Read the size of the list vector<long long> a(n); REP(i, 0,n){ cin >> a[i]; } int maxBits = 0; pair<long long, long long> bestPair; REP(i, 0, n){ for(int j = i + 1; j < n; j++) { long long product = a[i] * a[j]; int bitsCount = countBits(product); if(bitsCount > maxBits) { maxBits = bitsCount; bestPair = {a[i], a[j]}; } } } cout << maxBits << endl; cout << bestPair.first << " " << bestPair.second << endl; 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 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 |
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 |
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 |