/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 3ms 740.0 KiB

Code

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T; 
    cin >> T;
    while(T--){
        int N;
        cin >> N;
        vector<int> A(N);
        int maxA = 0;
        for(int i = 0; i < N; i++){
            cin >> A[i];
            maxA = max(maxA, A[i]);
        }

        // how many we need in odd/even slots
        int kodd  = (N+1)/2;
        int keven = N/2;

        // frequency of values
        vector<int> freq(maxA+1, 0);
        for(int x: A) freq[x]++;

        // cnt[d] = # of A[i] divisible by d
        vector<int> cnt(maxA+1, 0);
        for(int d = 1; d <= maxA; d++){
            for(int m = d; m <= maxA; m += d)
                cnt[d] += freq[m];
        }

        // find best X, Y
        int bestX = 1;  // gcd at least 1 always possible
        for(int d = 1; d <= maxA; d++){
            if(cnt[d] >= kodd)
                bestX = d;
        }
        int bestY = 1;
        for(int d = 1; d <= maxA; d++){
            if(cnt[d] >= keven)
                bestY = d;
        }

        cout << (bestX + bestY) << "\n";
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1077 Even Odd GCD (Hard Version)
Language
C++17 (G++ 13.2.0)
Submit At
2025-05-24 10:19:12
Judged At
2025-05-24 10:19:12
Judged By
Score
0
Total Time
3ms
Peak Memory
740.0 KiB