/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 86ms 16.77 MiB
#2 Accepted 99ms 16.664 MiB
#3 Accepted 112ms 16.891 MiB
#4 Accepted 91ms 16.863 MiB
#5 Accepted 73ms 16.816 MiB
#6 Accepted 106ms 16.816 MiB
#7 Accepted 108ms 16.75 MiB
#8 Accepted 83ms 16.922 MiB
#9 Accepted 88ms 16.902 MiB
#10 Accepted 91ms 16.84 MiB
#11 Accepted 105ms 16.906 MiB
#12 Accepted 113ms 16.789 MiB
#13 Accepted 87ms 16.746 MiB
#14 Accepted 84ms 16.766 MiB
#15 Accepted 108ms 17.051 MiB
#16 Accepted 103ms 16.988 MiB
#17 Accepted 273ms 17.652 MiB
#18 Accepted 97ms 16.855 MiB
#19 Accepted 141ms 17.105 MiB
#20 Accepted 116ms 17.043 MiB
#21 Accepted 132ms 17.113 MiB
#22 Accepted 104ms 17.008 MiB
#23 Accepted 151ms 17.113 MiB
#24 Accepted 132ms 17.117 MiB
#25 Accepted 102ms 17.035 MiB
#26 Accepted 128ms 17.199 MiB
#27 Accepted 126ms 17.07 MiB
#28 Accepted 108ms 17.117 MiB
#29 Accepted 141ms 17.086 MiB
#30 Accepted 175ms 17.512 MiB
#31 Accepted 141ms 17.539 MiB
#32 Accepted 107ms 16.836 MiB
#33 Accepted 131ms 17.633 MiB
#34 Accepted 101ms 17.031 MiB
#35 Accepted 257ms 17.672 MiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using minheap = priority_queue<long long, vector<long long>, greater<long long>>;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define ll long long
#define ld long double
#define MOD 1000000007
#define pie 2*(acos(0.0))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define endl '\n'
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define print(v) for(auto e:v) cout<<e<<" "; cout<<endl;
#define printp(v) for(auto e:v) cout<<e.first<<" "<<e.second<<endl;
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define life_is_a_race ios::sync_with_stdio(false); cin.tie(nullptr);

vector<vector<ll>> alldiv(100006);
void alldivisor()
{
    for(int i=1;i<=100000;i++) alldiv[i].push_back(1);
    for(int i=2;i<=100000;i++)
    {
        alldiv[i].push_back(i);
        for(int j=i+i;j<=100000;j+=i) alldiv[j].push_back(i);
    }
}

bool cmp(pair<ll,ll>&a,pair<ll,ll>&b) {return a>b;}

void solve(int tc)
{
    //cout<<"Case "<<tc<<": ";
    ll n; cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<ll> hash(100005);

    for(int i=0;i<n;i++)
    {
        for(auto e:alldiv[a[i]])
        {
            hash[e]++;
        }
    }

    vector<pair<ll,ll>> v;
    for(int i=1;i<=100000;i++)
    {
        if(hash[i] >= (n/2)) 
        {
            v.push_back({hash[i],i});
        }
    }

    sort(v.begin(),v.end(),cmp);
    //printp(v);
    ll ans = 2;

    int m = v.size();
    for(int i=0;i<m;i++)
    {
        //cout << v[i].first <<" "<< v[i].second<<endl;
        //if(v[i].first < (n+1)/2) break;

        for(int j=i;j<m;j++)
        {
            //cout << v[j].first <<" "<<v[j].second<<endl;
            //if(v[j].first < n/2) break;
            ll lcmm = lcm(v[i].second,v[j].second);
            ll cnt;
            if(lcmm > 100000) cnt = 0;
            else cnt = hash[lcmm];

            if(v[i].first + v[j].first - cnt >= n) 
            {
                ans = max(ans , v[i].second + v[j].second);
            }
        }
    }

    cout << ans << endl;

    //for(int i=1;i<=10;i++) cout << i << " "<<hash[i]<<endl;
}
int main()
{
    //life_is_a_race
    alldivisor();
    
    int t=1; 
    cin>>t;
    for(int i=1;i<=t;i++) solve(i);
}

Information

Submit By
Type
Submission
Problem
P1077 Even Odd GCD (Hard Version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-24 11:29:41
Judged At
2024-08-26 13:10:29
Judged By
Score
100
Total Time
273ms
Peak Memory
17.672 MiB