結果

問題 No.2718 Best Consonance
ユーザー GOTKAKO
提出日時 2024-04-05 22:37:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,278 ms / 4,000 ms
コード長 1,360 bytes
コンパイル時間 2,761 ms
コンパイル使用メモリ 212,932 KB
最終ジャッジ日時 2025-02-20 21:50:03
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N; cin >> N;
    vector<vector<long long>> AB(200001);
    for(int i=0; i<N; i++){
        int a,b; cin >> a >> b;
        AB.at(a).push_back(b);
    }

    vector<vector<pair<long long,long long>>> D(200001);
    for(int i=1; i<=200000; i++){
        long long a = i;
        sort(AB.at(i).rbegin(),AB.at(i).rend());
        vector<int> d;
        for(int k=1; k*k<=a; k++){
            if(a%k) continue;
            d.push_back(k);
            if(k*k != a) d.push_back(a/k);
        }
        for(int l=0; l<min((int)AB.at(i).size(),2); l++){
            long long b = AB.at(i).at(l);
            for(auto dd : d) D.at(dd).push_back({a*b,a});
        }
    }

    long long answer = 0;
    for(int i=1; i<=200000; i++){
        int n = D.at(i).size();
        vector<long long> mina(n);
        sort(D.at(i).begin(),D.at(i).end());
        for(int k=n-1; k>=0; k--){
            if(k != n-1) mina.at(k) = min(D.at(i).at(k).second,mina.at(k+1));
            else mina.at(k) = D.at(i).at(k).second;
        }

        for(int k=0; k<n-1; k++){
            auto[limit,a1] = D.at(i).at(k);
            auto[ign,a2] = D.at(i).at(k+1);
            answer = max(answer,limit/(a1*a2/i));
        }
    }
    cout << answer << endl;
}
0