結果

問題 No.2718 Best Consonance
ユーザー atug tokyo
提出日時 2024-06-26 19:29:20
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,906 ms / 4,000 ms
コード長 1,323 bytes
コンパイル時間 5,527 ms
コンパイル使用メモリ 317,076 KB
実行使用メモリ 284,360 KB
最終ジャッジ日時 2024-06-26 19:29:49
合計ジャッジ時間 28,674 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

// オリジナル: https://yukicoder.me/submissions/990891
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;  // 1000000007;
using ll = long long;
using pp = pair<int, int>;
#define sr string
#define vc vector
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main() {
  int n;
  cin >> n;
  vc<pp> v(n);
  for (auto& [a, b] : v) cin >> a >> b;
  int m = 2e5 + 5;
  vc d(m, vc<int>(0));
  for (int i = 1; i < m; i++)
    for (int j = i; j < m; j += i) d[j].pb(i);
  vc dx(m, vc<pp>(0));
  for (auto p : v)
    for (auto au : d[p.fi]) dx[au].pb(p);
  int ans = 0;
  for (int i = 1; i < m; i++)
    if (dx[i].size()) {
      auto& vx = dx[i];
      // sort にわたす比較関数は等しい場合は false を返すように実装します。
      // sort(all(vx),
      //      [&](pp a, pp b) { return (ll)a.fi * a.se >= (ll)b.fi * b.se; });
      sort(all(vx),
           [&](pp a, pp b) { return (ll)a.fi * a.se > (ll)b.fi * b.se; });
      int mn = 1e9 + 5;
      for (auto [a, b] : vx) {
        ans = max(ans, b / mn);
        mn = min(mn, a / i);
      }
    }
  cout << ans;
}
0