結果
| 問題 |
No.3073 Fraction Median
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-03-24 14:23:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,365 bytes |
| コンパイル時間 | 551 ms |
| コンパイル使用メモリ | 46,720 KB |
| 実行使用メモリ | 14,780 KB |
| 最終ジャッジ日時 | 2025-03-24 14:23:36 |
| 合計ジャッジ時間 | 6,603 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 TLE * 1 -- * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:47:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
47 | for (int i = 0; i < n; i++) scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3073.cc: No.3073 Fraction Median - yukicoder
*/
#include<cstdio>
#include<algorithm>
#include<numeric>
using namespace std;
/* constant */
const int MAX_N = 1500000;
const int CNT = 100;
const int INF = 1 << 30;
/* typedef */
using ll = long long;
/* global variables */
int as[MAX_N];
/* subroutines */
ll calc(int n, double f) {
ll sum = 0;
for (int i = 0; i < n; i++) {
int j = n;
if (as[i] * f < INF) {
int x = (int)(as[i] * f);
j = upper_bound(as, as + n, x) - as;
}
if (j > i) j--;
sum += j;
}
return sum;
}
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", as + i);
sort(as, as + n);
ll k = (ll)n * (n - 1) / 2;
double f0 = 0.0, f1 = 1e9 + 1;
for (int cnt = 0; cnt < CNT; cnt++) {
double f = (f0 + f1) / 2;
ll c = calc(n, f);
//printf(" f=%lf, c=%lld\n", f, c);
if (c < k) f0 = f;
else f1 = f;
}
//printf(" f1=%lf\n", f1);
int x = 0, y = 1;
for (int i = 0; i < n; i++) {
int fi = (int)(as[i] * f1);
int j = upper_bound(as, as + n, fi) - as;
//printf(" i=%d, j=%d\n", i, j);
while (--j >= 0)
if (i != j) {
if ((ll)as[j] * y > (ll)x * as[i]) x = as[j], y = as[i];
break;
}
}
int g = gcd(x, y);
x /= g, y /= g;
printf("%d %d\n", x, y);
return 0;
}
tnakao0123