/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 72ms 17.656 MiB
#2 Accepted 69ms 17.559 MiB
#3 Accepted 68ms 17.539 MiB
#4 Accepted 65ms 17.578 MiB
#5 Accepted 74ms 17.566 MiB
#6 Accepted 88ms 17.586 MiB
#7 Accepted 75ms 17.5 MiB
#8 Accepted 70ms 17.664 MiB
#9 Accepted 75ms 17.473 MiB
#10 Accepted 64ms 17.668 MiB
#11 Accepted 75ms 17.543 MiB
#12 Accepted 77ms 17.848 MiB
#13 Accepted 70ms 17.652 MiB
#14 Accepted 66ms 17.691 MiB
#15 Accepted 78ms 17.766 MiB
#16 Accepted 71ms 17.961 MiB
#17 Accepted 122ms 18.457 MiB
#18 Accepted 83ms 17.836 MiB
#19 Accepted 79ms 17.812 MiB
#20 Accepted 79ms 17.902 MiB
#21 Accepted 75ms 17.805 MiB
#22 Accepted 85ms 17.895 MiB
#23 Accepted 99ms 17.914 MiB
#24 Accepted 133ms 17.836 MiB
#25 Accepted 104ms 17.793 MiB
#26 Accepted 89ms 17.762 MiB
#27 Accepted 84ms 18.02 MiB
#28 Accepted 80ms 17.91 MiB
#29 Accepted 81ms 18.086 MiB
#30 Accepted 92ms 18.277 MiB
#31 Accepted 89ms 18.621 MiB
#32 Accepted 86ms 17.855 MiB
#33 Accepted 71ms 18.363 MiB
#34 Accepted 73ms 18.102 MiB
#35 Accepted 118ms 18.453 MiB

Code

/*For today, you happen to be the defeated. But what will you become tomorrow?*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define dbg if(debugg)
#define F first 
#define S second 
#define int long long
bool debugg = false;

template <typename T>
using order_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());  

const int N = 100005;
vector<int>divisors[N];
void sieve()
{
    for(int i = 1; i < N; i ++){
        for(int j = i; j < N; j += i){
            divisors[j].push_back(i);
        }
    }
}
int cnt[N], tot[N];
void solve()
{
    
    int n;
    cin >> n;
    vector<int>v(n);
    int gd = 0;
    memset(cnt, 0, sizeof(cnt));
    memset(tot, 0, sizeof(tot));
    for(int i = 0; i < n; i ++){
        cin >> v[i];
        gd = __gcd(gd, v[i]);
        cnt[v[i]] += 1;
    }

    for(int i = 1; i < N; i ++){
        for(int j = i; j < N; j += i){
            tot[i] += cnt[j];
        }
    }
    int ans = 2 * gd;
	assert(n > 0);
    for(int itr = 0; itr < 10; itr ++){
        int x = v[rng() % n], y = v[rng() % n];
        for(int i : divisors[x]){
            for(int j : divisors[y]){
                
                if(i == j) continue;
                int lm = (1ll * i * j) / gcd(i, j);
                if(lm >= N) lm = 0;
				assert(lm < N);
                if(tot[i] + tot[j] - tot[lm] != n) continue;
                int p = tot[i], q = tot[j];
                if(max(p, q) >= ((n + 1) / 2)){
                    if(min(p, q) >= (n / 2)){
                        ans = max(ans, i + j);
                    }
                }
                
            }
        }
    }

    cout << ans << '\n';
}



int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t  = 1;
    cin>>t;

    sieve();

    while(t--){

        solve();

    }

    return 0;

}

Information

Submit By
Type
Submission
Problem
P1077 Even Odd GCD (Hard Version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-17 05:59:52
Judged At
2024-08-17 05:59:52
Judged By
Score
100
Total Time
133ms
Peak Memory
18.621 MiB