結果

問題 No.2718 Best Consonance
ユーザー shobonvipshobonvip
提出日時 2024-04-06 09:55:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,242 ms / 4,000 ms
コード長 1,713 bytes
コンパイル時間 5,293 ms
コンパイル使用メモリ 262,236 KB
実行使用メモリ 35,196 KB
最終ジャッジ日時 2024-04-10 10:56:55
合計ジャッジ時間 10,868 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 270 ms
26,216 KB
testcase_01 AC 286 ms
26,216 KB
testcase_02 AC 292 ms
26,256 KB
testcase_03 AC 291 ms
26,156 KB
testcase_04 AC 271 ms
26,088 KB
testcase_05 AC 270 ms
26,248 KB
testcase_06 AC 274 ms
26,400 KB
testcase_07 AC 286 ms
26,396 KB
testcase_08 AC 279 ms
26,432 KB
testcase_09 AC 292 ms
26,284 KB
testcase_10 AC 266 ms
26,292 KB
testcase_11 AC 265 ms
26,212 KB
testcase_12 AC 271 ms
26,324 KB
testcase_13 AC 261 ms
26,196 KB
testcase_14 AC 522 ms
34,672 KB
testcase_15 AC 449 ms
32,468 KB
testcase_16 AC 477 ms
33,576 KB
testcase_17 AC 393 ms
31,220 KB
testcase_18 AC 481 ms
33,448 KB
testcase_19 AC 424 ms
32,180 KB
testcase_20 AC 518 ms
34,532 KB
testcase_21 AC 472 ms
33,300 KB
testcase_22 AC 486 ms
33,868 KB
testcase_23 AC 429 ms
30,636 KB
testcase_24 AC 466 ms
35,064 KB
testcase_25 AC 520 ms
34,040 KB
testcase_26 AC 548 ms
34,464 KB
testcase_27 AC 530 ms
35,000 KB
testcase_28 AC 579 ms
34,352 KB
testcase_29 AC 552 ms
34,356 KB
testcase_30 AC 540 ms
33,960 KB
testcase_31 AC 540 ms
34,876 KB
testcase_32 AC 579 ms
34,480 KB
testcase_33 AC 546 ms
35,196 KB
testcase_34 AC 270 ms
26,184 KB
testcase_35 AC 280 ms
26,260 KB
testcase_36 AC 557 ms
35,100 KB
testcase_37 AC 243 ms
26,312 KB
testcase_38 AC 1,242 ms
34,368 KB
testcase_39 AC 307 ms
26,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n; cin >> n;
	vector<tuple<ll,ll,ll>> tar;
	rep(i,0,n){
		ll a, b; cin >> a >> b;
		tar.push_back(make_tuple(a * b, a, b));
	}
	
	sort(tar.begin(), tar.end());
	reverse(tar.begin(), tar.end());

	vector<ll> a(n), b(n);
	rep(i,0,n){
		a[i] = get<1>(tar[i]);
		b[i] = get<2>(tar[i]);
	}

	const int mx = 200000;
	vector<ll> see(mx + 1, 1e18);

	vector<vector<int>> d(mx + 1);
	rep(i,1,mx+1){
		for (int j=i; j<=mx; j+=i){
			d[j].push_back(i);
		}
	}

	ll ans = 0;
	rep(i,0,n){
		for (int j: d[a[i]]){
			// A[x] / j = GCD
			if (see[j] < 1e12){
				chmax(ans, (a[i] * b[i]) / (see[j] * a[i]));
			}
			chmin(see[j], a[i] / j);
		}
	}
	cout << ans << '\n';
}

0