/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 72ms 16.922 MiB
#2 Accepted 72ms 16.77 MiB
#3 Accepted 71ms 16.719 MiB
#4 Accepted 72ms 16.719 MiB
#5 Accepted 72ms 16.676 MiB
#6 Accepted 71ms 16.914 MiB
#7 Accepted 73ms 16.898 MiB
#8 Wrong Answer 72ms 16.902 MiB
#9 Accepted 72ms 16.68 MiB
#10 Accepted 72ms 16.859 MiB
#11 Accepted 73ms 16.918 MiB
#12 Accepted 71ms 16.727 MiB
#13 Accepted 72ms 16.77 MiB
#14 Accepted 76ms 16.914 MiB
#15 Accepted 81ms 16.965 MiB
#16 Accepted 86ms 17.098 MiB
#17 Accepted 154ms 17.688 MiB
#18 Accepted 73ms 16.902 MiB
#19 Accepted 84ms 16.938 MiB
#20 Accepted 82ms 16.973 MiB
#21 Accepted 83ms 17.113 MiB
#22 Accepted 84ms 17.098 MiB
#23 Accepted 84ms 16.992 MiB
#24 Accepted 85ms 17.035 MiB
#25 Accepted 80ms 16.996 MiB
#26 Accepted 85ms 17.121 MiB
#27 Accepted 90ms 17.117 MiB
#28 Accepted 88ms 17.055 MiB
#29 Accepted 88ms 17.152 MiB
#30 Accepted 126ms 17.66 MiB
#31 Accepted 104ms 17.676 MiB
#32 Accepted 91ms 16.953 MiB
#33 Accepted 88ms 17.512 MiB
#34 Accepted 77ms 16.992 MiB
#35 Accepted 134ms 17.598 MiB

Code

#include <bits/stdc++.h>

#ifdef LOCAL
#include "template.cpp.h"
#else
#define debug(...)
#endif

#define int long long
using namespace std;
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';

const int N = 1e5 + 5;
vector<int> divisors[N];
int cnt[N];
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

void shelby() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        for (auto &it: divisors[v[i]]) cnt[it]++;
    }
    int ans = 0;
    for (int random = 1; random <= 6; ++random) {
        int x = v[rng() % n], y = v[rng() % n];
        for (auto &i: divisors[x]) {
            for (auto &j: divisors[y]) {
                if (i == j) {
                    if (cnt[i] == n) ans = max(ans, 2 * i);
                    continue;
                }
                int a = cnt[i], b = cnt[j], l = lcm(i, j), c = (l < N ? cnt[l] : 0);
                if (a < b) swap(a, b);
                int extra = a - n / 2 - (n % 2);
                c -= extra;
                if (extra < 0 || c < 0) continue;
                b -= c;
                if (b == n / 2) ans = max(ans, i + j);
            }
        }
    }
    cout << ans << '\n';
    for (int i = 1; i < N; ++i) cnt[i] = 0;
}

signed main() {
    cin.tie(0)->ios_base::sync_with_stdio(0);
    for (int i = 1; i < N; ++i) {
        for (int j = i; j < N; j += i) divisors[j].push_back(i);
    }
    int t = 1;
    cin >> t;
    for (int _ = 1; _ <= t; ++_) {
//        cout << "Case " << _ << ": ";
        shelby();
    }
}

Information

Submit By
Type
Submission
Problem
P1077 Even Odd GCD (Hard Version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-17 11:48:03
Judged At
2024-08-17 11:48:03
Judged By
Score
96
Total Time
154ms
Peak Memory
17.688 MiB