結果
問題 |
No.3073 Fraction Median
|
ユーザー |
![]() |
提出日時 | 2025-03-22 16:19:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 696 ms / 2,500 ms |
コード長 | 2,028 bytes |
コンパイル時間 | 5,931 ms |
コンパイル使用メモリ | 333,588 KB |
実行使用メモリ | 32,712 KB |
最終ジャッジ日時 | 2025-03-22 16:19:24 |
合計ジャッジ時間 | 16,976 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; struct fraction { ll p, q; fraction(ll P = 0, ll Q = 1) : p(P), q(Q) { ll g = gcd(p, q); p /= g; q /= g; } bool operator<(const fraction &other) const { return p * other.q < other.p * q; } bool operator<=(const fraction &other) const { return p * other.q <= other.p * q; } bool operator>(const fraction &other) const { return p * other.q > other.p * q; } bool operator>=(const fraction &other) const { return p * other.q >= other.p * q; } bool operator==(const fraction &other) const { return p * other.q == other.p * q; } fraction operator+(const fraction &other) const { return fraction(p * other.q + other.p * q, q * other.q); } fraction operator-(const fraction &other) const { return fraction(p * other.q - other.p * q, q * other.q); } fraction operator*(const fraction &other) const { return fraction(p * other.p, q * other.q); } fraction operator/(const fraction &other) const { return fraction(p * other.q, q * other.p); } fraction operator+=(const fraction &other) { return *this = *this + other; } fraction operator-=(const fraction &other) { return *this = *this - other; } fraction operator*=(const fraction &other) { return *this = *this * other; } fraction operator/=(const fraction &other) { return *this = *this / other; } }; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int n; cin >> n; vector<int> a(n); rep(i, 0, n) cin >> a[i]; sort(a.begin(), a.end()); ll tar = (ll)n * (n - 1) / 2; vector<fraction> fs(n - 1); rep(i, 0, n - 1) { fs[i] = fraction(a[i], a[i + 1]); } sort(fs.begin(), fs.end()); auto ans = fs.back(); cout << ans.p << " " << ans.q << endl; }