結果
| 問題 |
No.3073 Fraction Median
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-21 23:32:49 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,675 bytes |
| コンパイル時間 | 6,287 ms |
| コンパイル使用メモリ | 333,948 KB |
| 実行使用メモリ | 22,408 KB |
| 最終ジャッジ日時 | 2025-03-21 23:33:02 |
| 合計ジャッジ時間 | 12,401 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 1 TLE * 1 -- * 13 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i >= n; i--)
#define inr(l, x, r) (l <= x && x < r)
#define ll long long
#define ld long double
// using mint = modint1000000007;
using mint = modint998244353;
constexpr int IINF = 1001001001;
constexpr ll INF = 1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
ll gcd(ll a, ll b){
if(a%b == 0) return b;
else return gcd(b, a%b);
}
int main(){
ll n; cin >> n;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
sort(a.begin(), a.end());
long double ok = 0.0, ng = 2e9;
while(ng-ok > 1e-10){
long double mid = (ok+ng)/2;
ll cnt = 0;
rep(i, 0, n){
// */a[i] <= mid の個数を調べる
ll thl = mid*a[i];
auto itr = upper_bound(a.begin(), a.end(), thl);
// cout << mid << ' ' << a[i] << ' ' << thl << endl;
cnt += itr-a.begin();
if(a[i] <= thl) cnt--;
}
if(cnt < n*(n-1)/2) ok = mid;
else ng = mid;
}
long double mi = 1e18;
pair<int, int> ans;
rep(i, 0, n){
ll thl = ok*a[i];
auto itr = upper_bound(a.begin(), a.end(), thl);
if(itr != a.end()){
if(mi > abs(ok-(long double)(*itr)/a[i])){
ans = {*itr, a[i]};
mi = abs(ok-(long double)(*itr)/a[i]);
}
}
}
int g = gcd(ans.first, ans.second);
cout << ans.first/g << ' ' << ans.second/g << endl;
return 0;
}