結果

問題 No.2718 Best Consonance
ユーザー ecotteaecottea
提出日時 2024-01-31 19:47:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 4,000 ms
コード長 1,653 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 209,892 KB
実行使用メモリ 14,912 KB
最終ジャッジ日時 2024-04-10 10:49:21
合計ジャッジ時間 10,351 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 236 ms
10,536 KB
testcase_15 AC 195 ms
9,744 KB
testcase_16 AC 214 ms
9,884 KB
testcase_17 AC 172 ms
10,132 KB
testcase_18 AC 221 ms
10,548 KB
testcase_19 AC 187 ms
9,676 KB
testcase_20 AC 234 ms
11,184 KB
testcase_21 AC 223 ms
10,420 KB
testcase_22 AC 230 ms
10,328 KB
testcase_23 AC 160 ms
9,464 KB
testcase_24 AC 306 ms
13,852 KB
testcase_25 AC 291 ms
14,232 KB
testcase_26 AC 293 ms
13,976 KB
testcase_27 AC 293 ms
14,228 KB
testcase_28 AC 295 ms
14,780 KB
testcase_29 AC 293 ms
13,848 KB
testcase_30 AC 297 ms
13,592 KB
testcase_31 AC 289 ms
14,912 KB
testcase_32 AC 289 ms
14,488 KB
testcase_33 AC 295 ms
14,104 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 8 ms
6,944 KB
testcase_36 AC 152 ms
7,168 KB
testcase_37 AC 9 ms
6,940 KB
testcase_38 AC 155 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS

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


int main() {
	int n;
	cin >> n;
	assert(2 <= n && n <= (int)2e5);

	vector<int> a(n); vector<long long> b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		assert(1 <= a[i] && a[i] <= (int)2e5);
		assert(1 <= b[i] && b[i] <= (long long)1e9);
	}

	int a_max = *max_element(a.begin(), a.end());

	long long res = 0;

	// 各 A[i] に対して最大の B[i] を対応付ける.
	vector<long long> a_to_bmax(a_max + 1, -1);
	for (int i = 0; i < n; i++) {
		if (a_to_bmax[a[i]] == -1) {
			a_to_bmax[a[i]] = b[i];
		}
		else {
			// それと同時に A[i] = A[j] のタイプを先に処理する.
			res = max(res, min(a_to_bmax[a[i]], b[i]));

			a_to_bmax[a[i]] = max(a_to_bmax[a[i]], b[i]);
		}
	}

	// A[i] と A[j] の公約数 g を決め打つ.
	for (int g = 1; 2 * g <= a_max; g++) {
		// (A[i], B[i]) を積 A[i] B[i] について昇順ソートする.
		vector<tuple<long long, int, long long>> ab_a_b;
		for (int a = g; a <= a_max; a += g) {
			long long b = a_to_bmax[a];
			if (b == -1) continue;

			ab_a_b.emplace_back(a * b, a, b);
		}
		sort(ab_a_b.begin(), ab_a_b.end());
		int K = (int)ab_a_b.size();

		// A[i] の上からの累積最小値を求める.
		vector<int> a_min(K + 1);
		a_min[K] = a_max + 1;
		for (int k = K - 1; k >= 0; k--) {
			auto [ab, a, b] = ab_a_b[k];
			a_min[k] = min(a_min[k + 1], a);
		}

		// 各 A[i] を採用する場合の調和度の最大値を求める.
		for (int k = 0; k < K - 1; k++) {
			auto [ab, a, b] = ab_a_b[k];
			res = max(res, (b * g) / a_min[k + 1]);
		}
	}

	cout << res << endl;
}
0