結果
問題 | No.2970 三次関数の絶対値 |
ユーザー | miya145592 |
提出日時 | 2024-11-29 22:34:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 12,323 bytes |
コンパイル時間 | 419 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 54,656 KB |
最終ジャッジ日時 | 2024-11-29 22:34:45 |
合計ジャッジ時間 | 3,977 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
53,760 KB |
testcase_01 | AC | 42 ms
53,888 KB |
testcase_02 | AC | 43 ms
54,528 KB |
testcase_03 | AC | 42 ms
54,144 KB |
testcase_04 | AC | 43 ms
53,760 KB |
testcase_05 | AC | 43 ms
53,868 KB |
testcase_06 | AC | 45 ms
54,016 KB |
testcase_07 | AC | 43 ms
53,504 KB |
testcase_08 | AC | 43 ms
54,528 KB |
testcase_09 | AC | 43 ms
54,528 KB |
testcase_10 | AC | 42 ms
54,144 KB |
testcase_11 | AC | 43 ms
54,016 KB |
testcase_12 | AC | 43 ms
53,944 KB |
testcase_13 | AC | 42 ms
54,400 KB |
testcase_14 | AC | 43 ms
53,796 KB |
testcase_15 | AC | 48 ms
53,668 KB |
testcase_16 | AC | 44 ms
53,760 KB |
testcase_17 | AC | 42 ms
53,504 KB |
testcase_18 | AC | 42 ms
53,760 KB |
testcase_19 | AC | 42 ms
53,888 KB |
testcase_20 | AC | 43 ms
53,888 KB |
testcase_21 | AC | 45 ms
54,144 KB |
testcase_22 | AC | 42 ms
53,888 KB |
testcase_23 | AC | 43 ms
53,760 KB |
testcase_24 | AC | 43 ms
53,720 KB |
testcase_25 | AC | 45 ms
53,888 KB |
testcase_26 | AC | 43 ms
53,888 KB |
testcase_27 | AC | 45 ms
54,656 KB |
testcase_28 | AC | 43 ms
54,528 KB |
testcase_29 | AC | 43 ms
54,016 KB |
testcase_30 | AC | 47 ms
54,400 KB |
testcase_31 | AC | 47 ms
53,992 KB |
testcase_32 | AC | 47 ms
54,272 KB |
testcase_33 | AC | 42 ms
53,796 KB |
testcase_34 | AC | 46 ms
54,400 KB |
testcase_35 | AC | 43 ms
53,760 KB |
testcase_36 | AC | 44 ms
54,656 KB |
testcase_37 | AC | 42 ms
54,528 KB |
testcase_38 | AC | 43 ms
53,504 KB |
testcase_39 | AC | 42 ms
53,760 KB |
testcase_40 | AC | 42 ms
54,144 KB |
testcase_41 | AC | 42 ms
54,144 KB |
testcase_42 | AC | 43 ms
54,144 KB |
testcase_43 | AC | 42 ms
53,760 KB |
testcase_44 | AC | 43 ms
53,760 KB |
testcase_45 | AC | 43 ms
54,400 KB |
testcase_46 | AC | 43 ms
54,016 KB |
testcase_47 | AC | 43 ms
53,888 KB |
testcase_48 | AC | 43 ms
54,144 KB |
testcase_49 | AC | 42 ms
54,400 KB |
ソースコード
def g(x): return C[3]*x*x*x+C[2]*x*x+C[1]*x+C[0] def f(x): global a, b, c return a*x*x+b*x+c import sys input = sys.stdin.readline C = list(map(int, input().split())) L, R = map(int, input().split()) if L==R: print(g(L)) exit() # ax^2+bx+c=0 c, b, a = C[1], C[2]*2, C[3]*3 D = b*b-4*a*c if D<0: # 実数解なし # 単調 v = f(L) if v>=0: # 増加 l = g(L) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) elif D>0: if a==0: # 1個 x = -c/b if R<=x: # L, R, x # 単調 v = f(L) if v>=0: # 増加 l = g(L) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) elif x<=L: # x, L, R # 単調 v = f(R) if v>=0: # 増加 l = g(L) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) else: # L, x, R # L<x v = f(L) if v>=0: # 増加 l = g(L) r = g(x) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(x) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) # x<R v = f(R) if v>=0: # 増加 l = g(x) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = min(ans, abs(l)) else: ans = min(ans, abs(r)) else: # 減少 l = g(x) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = min(ans, abs(r)) else: ans = min(ans, abs(l)) else: # 実数解あり x1 = (-b+D**0.5)/(2*a) x2 = (-b-D**0.5)/(2*a) if x1>x2: x1, x2 = x2, x1 if L<=x1: if R<=x1: # L, R, x1, x2 # 単調 v = f(L) w = f(R) if v>0 or w>0: # 増加 l = g(L) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) elif x2<R: # L, x1, x2, R # L<x1 v = f(L) if v>=0: # 増加 l = g(L) r = g(x1) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(x1) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) # x1<x2 mid = (x1+x2)/2 v = f(mid) if v>=0: # 増加 l = g(x1) r = g(x2) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = min(ans, abs(l)) else: ans = min(ans, abs(r)) else: # 減少 l = g(x1) r = g(x2) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = min(ans, abs(r)) else: ans = min(ans, abs(l)) # x2<R v = f(R) if v>=0: # 増加 l = g(x2) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = min(ans, abs(l)) else: ans = min(ans, abs(r)) else: # 減少 l = g(x2) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = min(ans, abs(r)) else: ans = min(ans, abs(l)) else: # L, x1, R, x2 # L<x1 v = f(L) if v>=0: # 増加 l = g(L) r = g(x1) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(x1) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) # x1<R v = f(R) if v>=0: # 増加 l = g(x1) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = min(ans, abs(l)) else: ans = min(ans, abs(r)) else: # 減少 l = g(x1) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = min(ans, abs(r)) else: ans = min(ans, abs(l)) elif x2<=L: # x1, x2, L, R # 単調 v = f(L) w = f(R) if v>0 or w>0: # 増加 l = g(L) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) else: if x2<R: # x1, L, x2, R # L<x2 v = f(L) if v>=0: # 増加 l = g(L) r = g(x2) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(x2) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) # x2<R v = f(R) if v>=0: # 増加 l = g(x2) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = min(ans, abs(l)) else: ans = min(ans, abs(r)) else: # 減少 l = g(x2) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = min(ans, abs(r)) else: ans = min(ans, abs(l)) else: # x1, L, R, x2 # 単調 v = f(L) w = f(R) if v>0 or w>0: # 増加 l = g(L) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) else: # 1個 # 単調 v = f(L) w = f(R) if v>0 or w>0: # 増加 l = g(L) r = g(R) if l<=0 and 0<=r: ans = 0 else: if l>0: ans = abs(l) else: ans = abs(r) else: # 減少 l = g(L) r = g(R) if r<=0 and 0<=l: ans = 0 else: if l>0: ans = abs(r) else: ans = abs(l) print(ans)