結果
| 問題 |
No.3073 Fraction Median
|
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2025-03-22 16:13:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,665 bytes |
| コンパイル時間 | 6,178 ms |
| コンパイル使用メモリ | 332,460 KB |
| 実行使用メモリ | 39,988 KB |
| 最終ジャッジ日時 | 2025-03-22 16:14:08 |
| 合計ジャッジ時間 | 11,893 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 TLE * 1 -- * 13 |
ソースコード
#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());
fraction ans = fraction(1, 1);
ll tar = (ll)n * (n - 1) / 2;
auto f = [&](fraction p) {
ll cnt = 0;
rep(i, 0, n) {
int ac = -1, wa = n;
while (wa - ac > 1) {
int m = ac + (wa - ac) / 2;
if (fraction(a[m], a[i]) > p)
wa = m;
else
ac = m;
}
cnt += ac + 1;
}
if (cnt >= tar)
ans = min(ans, p);
return (cnt >= tar);
};
vector<fraction> fs(n - 1);
rep(i, 0, n - 1) { fs[i] = fraction(a[i], a[i + 1]); }
sort(fs.begin(), fs.end());
int wa = -1, ac = n;
while (ac - wa > 1) {
int m = wa + (ac - wa) / 2;
if (f(fs[m]))
ac = m;
else
wa = m;
}
cout << ans.p << " " << ans.q << endl;
}
SnowBeenDiding