/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 3ms 532.0 KiB
#3 Accepted 20ms 444.0 KiB
#4 Accepted 19ms 320.0 KiB
#5 Accepted 20ms 552.0 KiB
#6 Accepted 19ms 560.0 KiB
#7 Accepted 20ms 556.0 KiB
#8 Accepted 31ms 532.0 KiB
#9 Accepted 44ms 560.0 KiB
#10 Accepted 84ms 556.0 KiB
#11 Accepted 295ms 564.0 KiB
#12 Accepted 296ms 560.0 KiB
#13 Accepted 143ms 324.0 KiB
#14 Accepted 148ms 568.0 KiB
#15 Accepted 151ms 560.0 KiB
#16 Accepted 167ms 560.0 KiB
#17 Accepted 152ms 568.0 KiB
#18 Accepted 166ms 560.0 KiB
#19 Accepted 148ms 564.0 KiB

Code

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

void solve() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1; i <= 100; i++) {
        for(int j = i; j <= 100; j++) {
            int x = 0, y = 0, z = 0;
            for(int k = 1; k <= n; k++) {
                if(a[k] % i == 0 and a[k] % j == 0) z++;
                else if(a[k] % i == 0) x++;
                else if(a[k] % j == 0) y++;
            }
            int r1 = max(0,(n+1)/2 - x);
            int r2 = max(0,n/2 - y);
            if(r1 + r2 == z) ans = max(ans,i+j);

            r1 = max(0,n/2 - x);
            r2 = max(0,(n+1)/2 - y);
            if(r1 + r2 == z) ans = max(ans,i+j);
        }
    }
    cout << ans << '\n';
    return;
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int tc = 1;
    cin >> tc;
    for(int kase = 1; kase <= tc; kase++) {
        //cout << "Case " << kase << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1076 Even Odd GCD (Easy Version)
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 17:18:26
Judged At
2024-11-11 03:12:06
Judged By
Score
100
Total Time
296ms
Peak Memory
568.0 KiB