結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 H20H20
提出日時 2022-03-08 11:19:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,025 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 86,712 KB
実行使用メモリ 91,680 KB
最終ジャッジ日時 2023-09-30 17:00:16
合計ジャッジ時間 14,840 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 220 ms
88,836 KB
testcase_02 AC 224 ms
91,156 KB
testcase_03 AC 224 ms
90,956 KB
testcase_04 AC 222 ms
90,840 KB
testcase_05 AC 223 ms
91,492 KB
testcase_06 WA -
testcase_07 AC 222 ms
90,780 KB
testcase_08 AC 231 ms
91,064 KB
testcase_09 AC 227 ms
90,960 KB
testcase_10 AC 227 ms
90,652 KB
testcase_11 AC 225 ms
90,984 KB
testcase_12 AC 229 ms
90,888 KB
testcase_13 AC 230 ms
90,760 KB
testcase_14 AC 232 ms
90,980 KB
testcase_15 AC 237 ms
90,660 KB
testcase_16 AC 230 ms
91,052 KB
testcase_17 AC 233 ms
91,020 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

'''
三分探索の抽象化ライブラリ
domain:= 定義域が整数(0)or実数(1)
searchtype:= 狭義に凹で最大値を求めたい(0)or狭義に凸で最小値を求めたい(1)
f:= 最大または最小にしたい値を返す
l,r:= 探索範囲(l<=r)
eps:= 誤差(整数なら2,実数なら誤差指定による)
iter:= 探索回数
op1:= 割り算の演算子
op2:= 反転させるかどうか(0の時反転)
op3:= 出力での反転
value:= 三分探索の解
args:= fの引数(iterable)…f(i,args)という形でargsを展開
'''
from operator import floordiv,truediv,truth,not_
from math import log
from unicodedata import decimal
class ternary_search:
    def __init__(self,domain,searchtype,f,l,r,eps,args=None):
        self.domain=domain
        self.searchtype=searchtype
        self.f=f
        self.l,self.r=l,r
        self.iter=int(log((r+1-l)/eps,1.5))+5
        self.args=args
        self.op1=[floordiv,truediv][domain]
        self.op2=[not_,truth][searchtype]
        self.op3=[max,min][searchtype]
        self.value=self.calc()
    def calc(self):
        for _ in range(self.iter):
            diff=self.op1(self.r-self.l,3)
            trisection1=self.l+diff
            trisection2=self.r-diff
            trisection1_value=self.f(trisection1,self.args)
            trisection2_value=self.f(trisection2,self.args)
            if self.op2(trisection1_value<=trisection2_value):
                self.r=trisection2
            if self.op2(trisection1_value>=trisection2_value):
                self.l=trisection1
        return self.op3([self.l,self.l+self.op1(self.r-self.l,2),self.r],key=lambda x:self.f(x,self.args))

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(N):
    A[i]*=10**20

X = 0
def f(x,arg):
    global X
    X = x
    ret=0
    for i in range(N):
        ret+=B[i]*abs(A[i]-x)
    return ret

import decimal
e=ternary_search(0,1,f,-10**40,10**40,2)
print(X/decimal.Decimal(10**20),(f(e.value,None)+100)//10**20)




0