/ SeriousOJ /

Record Detail

System Error


  
# Status Time Cost Memory Cost
#1 Accepted 51ms 11.082 MiB
#2 Accepted 44ms 10.855 MiB
#3 Accepted 49ms 11.086 MiB
#4 Accepted 54ms 10.961 MiB
#5 Accepted 50ms 11.02 MiB
#6 Accepted 72ms 10.98 MiB
#7 Accepted 52ms 10.906 MiB
#8 Accepted 52ms 11.012 MiB
#9 Accepted 57ms 11.152 MiB
#10 Accepted 53ms 10.902 MiB
#11 Accepted 53ms 10.988 MiB
#12 Accepted 46ms 10.941 MiB
#13 Accepted 53ms 10.973 MiB
#14 Accepted 58ms 10.93 MiB
#15 Accepted 58ms 11.074 MiB
#16 Accepted 57ms 11.207 MiB
#17 Accepted 126ms 11.473 MiB
#18 Accepted 72ms 11.078 MiB
#19 Accepted 68ms 11.148 MiB
#20 Accepted 69ms 11.195 MiB
#21 Accepted 59ms 11.176 MiB
#22 Accepted 69ms 11.18 MiB
#23 System Error 47ms 11.152 MiB
#24 System Error 51ms 11.02 MiB
#25 System Error 52ms 11.441 MiB
#26 Accepted 60ms 11.121 MiB
#27 Accepted 73ms 11.082 MiB
#28 Accepted 78ms 11.211 MiB
#29 Accepted 67ms 11.145 MiB
#30 Accepted 84ms 11.441 MiB
#31 Accepted 76ms 11.414 MiB
#32 Accepted 60ms 10.969 MiB
#33 System Error 58ms 11.723 MiB
#34 Accepted 54ms 11.055 MiB
#35 Accepted 115ms 11.387 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 <= 10; ++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:06:53
Judged At
2024-08-17 11:06:53
Judged By
Score
88
Total Time
126ms
Peak Memory
11.723 MiB