結果

問題 No.2970 三次関数の絶対値
コンテスト
ユーザー ecottea
提出日時 2024-11-30 03:14:42
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,562 ms / 2,000 ms
+ 461µs
コード長 480 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 58 ms
コンパイル使用メモリ 14,848 KB
実行使用メモリ 81,204 KB
最終ジャッジ日時 2026-10-02 09:03:31
合計ジャッジ時間 81,478 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://mirucacule.hatenablog.com/entry/2021/09/14/183909

import numpy as np
from scipy.optimize import minimize

c0, c1, c2, c3 = map(int, input().split())
l, r = map(int, input().split())

def f(x):
    return abs(c0 + c1 * x + c2 * x**2 + c3 * x**3)

div = 100
x = np.linspace(l, r, div)
y = f(x)
x0 = l + ((r - l) / div) * (np.argmin(y) + 1) # initial point
bnds = ((l, r),)
res = minimize(f, x0, method='Nelder-Mead', bounds=bnds, tol=1e-5)

print('{:f}'.format(res.fun))
0