結果
問題 | No.2718 Best Consonance |
ユーザー |
![]() |
提出日時 | 2024-04-06 12:59:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 255 ms / 4,000 ms |
コード長 | 1,023 bytes |
コンパイル時間 | 2,193 ms |
コンパイル使用メモリ | 202,104 KB |
最終ジャッジ日時 | 2025-02-20 22:32:31 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}int main() {fast_io();int n;cin >> n;const int M = 2e5;vector<int> b(M + 1);long long ans = 0;for (int i = 0; i < n; i++) {int a, bb;cin >> a >> bb;ans = max(ans, (long long)min(bb, b[a]));b[a] = max(b[a], bb);}using pll = pair<long long, long long>;for (int g = 1; g <= M; g++) {vector<pll> ab;for (int i = g; i <= M; i += g) {if (b[i] > 0) {ab.push_back({i, b[i]});}}if (ab.size() < 2) {continue;}sort(ab.begin(), ab.end(), [&](pll a, pll b) {return a.first * a.second < b.first * b.second;});long long b_ma = 0;for (auto [a, b] : ab) {ans = max(ans, b_ma / (a / g));b_ma = max(b_ma, b);}}cout << ans << endl;}