結果

問題 No.1478 Simple Sugoroku
ユーザー 👑 H20H20
提出日時 2023-05-31 17:56:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,910 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 93,884 KB
最終ジャッジ日時 2023-08-28 01:36:00
合計ジャッジ時間 8,079 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,432 KB
testcase_01 AC 73 ms
71,784 KB
testcase_02 AC 75 ms
71,456 KB
testcase_03 AC 76 ms
71,144 KB
testcase_04 AC 75 ms
71,112 KB
testcase_05 AC 75 ms
71,324 KB
testcase_06 AC 74 ms
71,376 KB
testcase_07 AC 75 ms
71,476 KB
testcase_08 AC 75 ms
71,788 KB
testcase_09 AC 76 ms
71,524 KB
testcase_10 AC 75 ms
71,228 KB
testcase_11 AC 75 ms
71,452 KB
testcase_12 AC 74 ms
71,600 KB
testcase_13 AC 102 ms
93,884 KB
testcase_14 AC 101 ms
93,600 KB
testcase_15 AC 101 ms
93,568 KB
testcase_16 AC 101 ms
93,408 KB
testcase_17 AC 100 ms
93,668 KB
testcase_18 AC 100 ms
93,580 KB
testcase_19 AC 100 ms
93,684 KB
testcase_20 AC 100 ms
93,456 KB
testcase_21 AC 100 ms
93,444 KB
testcase_22 AC 99 ms
93,500 KB
testcase_23 AC 102 ms
93,636 KB
testcase_24 AC 100 ms
93,508 KB
testcase_25 AC 97 ms
93,680 KB
testcase_26 AC 98 ms
93,464 KB
testcase_27 AC 99 ms
93,548 KB
testcase_28 AC 97 ms
92,472 KB
testcase_29 AC 98 ms
92,656 KB
testcase_30 AC 98 ms
92,856 KB
testcase_31 AC 97 ms
92,924 KB
testcase_32 AC 99 ms
92,920 KB
testcase_33 AC 97 ms
93,188 KB
testcase_34 AC 98 ms
92,880 KB
testcase_35 AC 98 ms
92,884 KB
testcase_36 AC 99 ms
93,132 KB
testcase_37 AC 99 ms
93,008 KB
testcase_38 AC 100 ms
93,076 KB
testcase_39 AC 99 ms
93,184 KB
testcase_40 AC 98 ms
93,388 KB
権限があれば一括ダウンロードができます

ソースコード

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
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,M = map(int,input().split())
B = list(map(int,input().split()))[::-1]

def f(i,arg):
    if i==0:
        return N-1
    first = B[-1]-1
    mul = M/i
    temp = 0
    for b in B[:i]:
        temp+=N-b
    return first+mul+temp/i
e=ternary_search(0,1,f,0,M-1,2)
print(f(e.value,None))
0