結果

問題 No.2718 Best Consonance
ユーザー AerenAeren
提出日時 2024-04-05 22:48:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 4,000 ms
コード長 1,446 bytes
コンパイル時間 4,204 ms
コンパイル使用メモリ 296,652 KB
実行使用メモリ 28,404 KB
最終ジャッジ日時 2024-04-10 10:53:26
合計ジャッジ時間 18,132 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 244 ms
25,312 KB
testcase_01 AC 251 ms
25,408 KB
testcase_02 AC 249 ms
25,476 KB
testcase_03 AC 239 ms
25,368 KB
testcase_04 AC 244 ms
25,468 KB
testcase_05 AC 238 ms
25,320 KB
testcase_06 AC 227 ms
25,520 KB
testcase_07 AC 239 ms
25,364 KB
testcase_08 AC 223 ms
25,436 KB
testcase_09 AC 231 ms
25,444 KB
testcase_10 AC 237 ms
25,380 KB
testcase_11 AC 252 ms
25,384 KB
testcase_12 AC 245 ms
25,356 KB
testcase_13 AC 243 ms
25,352 KB
testcase_14 AC 354 ms
27,300 KB
testcase_15 AC 327 ms
26,952 KB
testcase_16 AC 332 ms
27,048 KB
testcase_17 AC 315 ms
26,656 KB
testcase_18 AC 332 ms
27,140 KB
testcase_19 AC 311 ms
26,776 KB
testcase_20 AC 355 ms
27,308 KB
testcase_21 AC 353 ms
27,100 KB
testcase_22 AC 347 ms
27,128 KB
testcase_23 AC 301 ms
26,668 KB
testcase_24 AC 373 ms
28,272 KB
testcase_25 AC 379 ms
28,272 KB
testcase_26 AC 372 ms
28,396 KB
testcase_27 AC 373 ms
28,272 KB
testcase_28 AC 385 ms
28,272 KB
testcase_29 AC 378 ms
28,396 KB
testcase_30 AC 382 ms
28,276 KB
testcase_31 AC 380 ms
28,276 KB
testcase_32 AC 375 ms
28,404 KB
testcase_33 AC 380 ms
28,400 KB
testcase_34 AC 241 ms
25,384 KB
testcase_35 AC 241 ms
25,188 KB
testcase_36 AC 286 ms
26,908 KB
testcase_37 AC 236 ms
25,464 KB
testcase_38 AC 283 ms
26,964 KB
testcase_39 AC 230 ms
25,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
template<class T> T &ctmin(T &x){ return x; }
template<class T, class Head, class ...Tail> T &ctmin(T &x, const Head &h, const Tail &... t){ return ctmin(x = min<T>(x, h), t...); }
template<class T> T &ctmax(T &x){ return x; }
template<class T, class Head, class ...Tail> T &ctmax(T &x, const Head &h, const Tail &... t){ return ctmax(x = max<T>(x, h), t...); }



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n;
	cin >> n;
	vector<vector<int>> div(200'001);
	for(auto x = 1; x <= 200'000; ++ x){
		for(auto y = x; y <= 200'000; y += x){
			div[y].push_back(x);
		}
	}
	vector<array<int, 2>> a(n);
	for(auto &[x, y]: a){
		cin >> x >> y;
	}
	int res = -1;
	{
		ranges::sort(a);
		vector<array<int, 2>> b;
		for(auto l = 0; l < n; ){
			int r = l;
			while(r < n && a[l][0] == a[r][0]){
				++ r;
			}
			if(r - l >= 2){
				ctmax(res, a[r - 2][1]);
			}
			b.push_back(a[r - 1]);
			l = r;
		}
		a = b;
	}
	ranges::sort(a, [&](auto p, auto q){ return 1LL * p[0] * p[1] > 1LL * q[0] * q[1]; });
	vector<int> opt(200'001, numeric_limits<int>::max());
	for(auto [x, y]: a){
		for(auto g: div[x]){
			ctmax(res, y / opt[g]);
		}
		for(auto g: div[x]){
			ctmin(opt[g], x / g);
		}
	}
	cout << res << "\n";
	return 0;
}

/*

*/
0