結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,092 KB
testcase_01 AC 35 ms
53,396 KB
testcase_02 AC 36 ms
52,944 KB
testcase_03 AC 33 ms
53,880 KB
testcase_04 AC 35 ms
53,860 KB
testcase_05 AC 35 ms
53,428 KB
testcase_06 AC 35 ms
53,308 KB
testcase_07 AC 34 ms
53,340 KB
testcase_08 AC 33 ms
53,600 KB
testcase_09 AC 34 ms
53,924 KB
testcase_10 WA -
testcase_11 AC 38 ms
53,064 KB
testcase_12 AC 35 ms
53,900 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**(-10))
    q=General_Binary_Increase_Search(-b/(2*a),10**100,lambda x:a*x**2+b*x+c>=0,False,10**(-10))
    print(p,q)
elif D==0:
    print(-b/(2*a))
else:
    print("imaginary")
0