/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 4ms 564.0 KiB
#3 Accepted 27ms 556.0 KiB
#4 Accepted 25ms 556.0 KiB
#5 Accepted 27ms 560.0 KiB
#6 Accepted 27ms 556.0 KiB
#7 Accepted 27ms 564.0 KiB
#8 Accepted 42ms 556.0 KiB
#9 Accepted 58ms 564.0 KiB
#10 Accepted 111ms 556.0 KiB
#11 Accepted 394ms 556.0 KiB
#12 Accepted 418ms 556.0 KiB
#13 Accepted 217ms 564.0 KiB
#14 Accepted 266ms 564.0 KiB
#15 Accepted 240ms 564.0 KiB
#16 Accepted 242ms 564.0 KiB
#17 Accepted 210ms 564.0 KiB
#18 Accepted 237ms 568.0 KiB
#19 Accepted 199ms 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-10-03 13:22:51
Judged By
Score
100
Total Time
418ms
Peak Memory
568.0 KiB