/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 588.0 KiB
#2 Accepted 305ms 552.0 KiB
#3 Accepted 278ms 540.0 KiB
#4 Accepted 260ms 556.0 KiB
#5 Accepted 256ms 548.0 KiB
#6 Accepted 257ms 584.0 KiB
#7 Accepted 55ms 544.0 KiB
#8 Accepted 52ms 540.0 KiB
#9 Accepted 51ms 604.0 KiB
#10 Accepted 52ms 580.0 KiB
#11 Accepted 52ms 540.0 KiB
#12 Accepted 33ms 1.277 MiB
#13 Accepted 37ms 1.301 MiB
#14 Accepted 101ms 1.32 MiB
#15 Accepted 107ms 1.293 MiB

Code

/*
 *   Copyright (c) 2025 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
//#define cout file

vector<int> generateBinaryOnes() {
    vector<int> ones;
    int limit = 2 * 1e9;
    int power = 1;
    while (true) {
        int val = (1 << power) - 1;
        if (val > limit) break;
        ones.push_back(val);
        power++;
    }
    return ones;
}

int findMaxProduct(const vector<int>& nums) {
    vector<int> ones = generateBinaryOnes();
    unordered_set<int> numSet(nums.begin(), nums.end());
    
    for (int num : nums) {
        for (int target : ones) {
            int diff = target - num;
            if (numSet.count(diff)) {
                return 1;
            }
        }
    }
    return 0;
}

void solve(int tc) {
    // string outp = "output"+to_string(tc)+".txt";
    // string inp = "input"+to_string(tc)+".txt";
    // ofstream file(outp);
    // freopen(inp.c_str(),"r",stdin);
    int t; cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        vector<int> arr(n);
        for(int i=0; i<n; ++i){
            cin >> arr[i];
        }
        cout << findMaxProduct(arr) << endl;
    }
}

int main()
{
    int l=0;
    int r=0;
    for(int i=l;i<=r;i++) solve(i);
}

Information

Submit By
Type
Submission
Problem
P1175 Maximum binary product of sum pairs
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-24 16:19:44
Judged At
2025-02-24 16:19:44
Judged By
Score
100
Total Time
305ms
Peak Memory
1.32 MiB