結果

問題 No.3073 Fraction Median
ユーザー detteiuu
提出日時 2025-03-21 22:21:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 709 ms / 2,500 ms
コード長 1,146 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 276,328 KB
最終ジャッジ日時 2025-03-21 22:21:53
合計ジャッジ時間 12,004 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

class Fraction:
    def __init__(self, top, bottom):
        self.top = top
        self.bottom = bottom

def compare(L, R):
    if type(L) == int:
        L = Fraction(L, 1)
    if type(R) == int:
        R = Fraction(R, 1)
    a = L.top*R.bottom
    b = L.bottom*R.top
    if a < b:
        return -1
    elif a == b:
        return 0
    else:
        return 1
    
def max_f(L, R):
    if type(L) == int:
        L = Fraction(L, 1)
    if type(R) == int:
        R = Fraction(R, 1)
    a = L.top*R.bottom
    b = L.bottom*R.top
    if a < b:
        return R
    else:
        return L

def min_f(L, R):
    if type(L) == int:
        L = Fraction(L, 1)
    if type(R) == int:
        R = Fraction(R, 1)
    a = L.top*R.bottom
    b = L.bottom*R.top
    if a < b:
        return L
    else:
        return R

N = int(input())
A = sorted(list(map(int, input().split())))

MAX = Fraction(1, 10**9*3)
for i in reversed(range(N-1)):
    if compare(Fraction(A[i], A[i+1]), MAX) == 1:
        MAX = Fraction(A[i], A[i+1])

top = MAX.top
bottom = MAX.bottom
GCD = gcd(top, bottom)
top //= GCD
bottom //= GCD

print(top, bottom)
0