結果

問題 No.2970 三次関数の絶対値
ユーザー lignan
提出日時 2024-12-18 13:10:58
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,092 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-12-18 13:11:04
合計ジャッジ時間 5,061 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
C0,C1,C2,C3=map(int,input().split())
L,R=map(int,input().split())

def f(x):
    return C0+C1*x+C2*x**2+C3*x**3
def absf(x):
    return abs(C0+C1*x+C2*x**2+C3*x**3)

if C3!=0:
    if C2**2-3*C1*C3>=0:
        X1=(-C2+sqrt(C2**2-3*C1*C3))/3/C3
        X2=(-C2-sqrt(C2**2-3*C1*C3))/3/C3
        X=[]
        if L<X1<R:
            X.append(X1)
        if L<X2<R:
            X.append(X2)
        flag=True
        for x in X:
            if not(f(L)>0 and f(R)>0 and f(x)>0) or not(f(L)<0 and f(R)<0 and f(x)<0) :
                flag=False
        if flag:
            print(0)
            exit()
        else:
            ans=min(absf(L),absf(R))
            for x in X:
                ans=min(ans,absf(x))
            print(ans)
            exit()
    else:
        ans=min(absf(L),absf(R))
        print(ans)
        exit()
        
else:
    if C2!=0:
        ans=min(absf(L),absf(R))
        X=-C1/2/C2
        if L<=X<=R:
            ans=min(ans,absf(X))
    else:
        if C1!=0:
            ans=min(absf(L),absf(R))
        else:
            ans=0
print(ans)

0