結果
問題 |
No.3073 Fraction Median
|
ユーザー |
![]() |
提出日時 | 2025-03-24 14:13:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,346 bytes |
コンパイル時間 | 680 ms |
コンパイル使用メモリ | 46,848 KB |
実行使用メモリ | 14,668 KB |
最終ジャッジ日時 | 2025-03-24 14:14:05 |
合計ジャッジ時間 | 8,163 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 2 WA * 2 TLE * 1 -- * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:43:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 43 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:44:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | 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 = 50; 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 x = (int)min(as[i] * f, (double)INF); int 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", f0); 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) { j--; if (i != j && (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; }