結果

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const int MAX=200000;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	vector<int>A(N);
	vector<ll>B(N);
	vector<pair<ll,int>>vp;
	for(int i=0;i<N;i++){
		cin>>A[i]>>B[i];
		vp.push_back(make_pair(A[i]*B[i],i));
	}
	sort(vp.begin(),vp.end());
	vector<int>at(MAX+1,-1);
	ll ans=0LL;
	for(auto[pd,i]:vp){
        for(int x=1;x*x<=A[i];x++){
            if(A[i]%x==0){
                if(at[x]==-1)at[x]=i;
                else{
                    chmax(ans,x*B[at[x]]/A[i]);
                    at[x]=i;
                }
                if(x*x<A[i]){
                    if(at[A[i]/x]==-1)at[A[i]/x]=i;
                    else{
                        chmax(ans,A[i]/x*B[at[A[i]/x]]/A[i]);
                        at[A[i]/x]=i;
                    }
                }
            }
        }
	}
	cout<<ans<<"\n";
}
0