結果

問題 No.1179 Quadratic Equation
ユーザー 👑 KazunKazun
提出日時 2020-08-21 21:37:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,924 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 53,740 KB
最終ジャッジ日時 2024-04-23 05:36:59
合計ジャッジ時間 1,150 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,608 KB
testcase_01 AC 33 ms
52,736 KB
testcase_02 AC 36 ms
53,120 KB
testcase_03 AC 38 ms
52,608 KB
testcase_04 AC 37 ms
52,352 KB
testcase_05 AC 36 ms
52,864 KB
testcase_06 AC 35 ms
52,480 KB
testcase_07 AC 34 ms
52,736 KB
testcase_08 AC 36 ms
52,736 KB
testcase_09 AC 36 ms
52,608 KB
testcase_10 WA -
testcase_11 AC 33 ms
52,480 KB
testcase_12 AC 33 ms
52,480 KB
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Increase_Search(L,R,cond,Integer=True,ep=1/(1<<20)):
    """条件式が単調増加であるとき,一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """
    if not(cond(R)):
        return False
        
    if Integer:
        R+=1
        while R-L>1:
            C=L+(R-L)//2
            if cond(C):
                R=C
            else:
                L=C
        return R
    else:
        while (R-L)>=ep:
            C=L+(R-L)/2
            if cond(C):
                R=C
            else:
                L=C
        return R

def General_Binary_Decrease_Search(L,R,cond,Integer=True,ep=1/(1<<20)):
    """条件式が単調減少であるとき,一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """

    if not(cond(L)):
        return False

    if Integer:
        L-=1
        while R-L>1:
            C=L+(R-L)//2
            if cond(C):
                L=C
            else:
                R=C
        return L
    else:
        while (R-L)>=ep:
            C=L+(R-L)/2
            if cond(C):
                L=C
            else:
                R=C
        return L
#==========================================================
from math import sqrt
a,b,c=map(int,input().split())

D=b*b-4*a*c
if D>0:
    p=General_Binary_Decrease_Search(-10*100,-b/(2*a),lambda x:a*x**2+b*x+c>=0,False,10**(-7))
    q=General_Binary_Increase_Search(-b/(2*a),10**100,lambda x:a*x**2+b*x+c>=0,False,10**(-7))
    print(p,q)
elif D==0:
    print(-b/(2*a))
else:
    print("imaginary")
0