結果

問題 No.2221 Set X
ユーザー FplusFplusFFplusFplusF
提出日時 2023-02-17 23:20:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 203,708 KB
最終ジャッジ日時 2025-02-10 18:12:05
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 4 WA * 14 TLE * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i=0;i<(long long)(n);i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
ll n;
vector<ll> a;
ll f(ll x){
    set<ll> st;
    rep(i,n) st.insert(a[i]/x);
    return (x+1)*st.size();
}
int main(){
    cin >> n;
    a.resize(n);
    vector<ll> v;
    rep(i,n){
        cin >> a[i];
        for(ll j=1;j*j<=a[i];j++){
            if(a[i]%j==0){
                v.push_back(j);
                v.push_back(a[i]/j);
            }
        }
    }
    pll ans={INF,f(a.back()+1)};
    mt19937 mt;
    rep(i,1000){
        ll x=mt()%v.size();
        chmin(ans,{f(v[x]),v[x]});
    }
    cout << ans.second << endl;
    cout << ans.first << endl;
}
0