結果

問題 No.463 魔法使いのすごろく🎲
ユーザー shotoyooshotoyoo
提出日時 2021-06-25 00:38:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 32,720 KB
最終ジャッジ日時 2023-09-07 13:31:32
合計ジャッジ時間 8,798 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
30,420 KB
testcase_01 AC 124 ms
29,912 KB
testcase_02 AC 120 ms
30,008 KB
testcase_03 AC 120 ms
30,028 KB
testcase_04 AC 122 ms
30,172 KB
testcase_05 AC 124 ms
30,316 KB
testcase_06 AC 122 ms
30,060 KB
testcase_07 AC 131 ms
29,944 KB
testcase_08 AC 123 ms
29,976 KB
testcase_09 AC 124 ms
32,088 KB
testcase_10 AC 123 ms
29,892 KB
testcase_11 AC 126 ms
31,740 KB
testcase_12 AC 124 ms
30,152 KB
testcase_13 AC 120 ms
30,088 KB
testcase_14 AC 120 ms
30,328 KB
testcase_15 AC 123 ms
30,532 KB
testcase_16 AC 119 ms
29,896 KB
testcase_17 AC 129 ms
30,424 KB
testcase_18 AC 128 ms
29,948 KB
testcase_19 AC 126 ms
29,956 KB
testcase_20 AC 128 ms
29,940 KB
testcase_21 AC 136 ms
32,212 KB
testcase_22 AC 128 ms
32,720 KB
testcase_23 AC 125 ms
30,508 KB
testcase_24 AC 122 ms
30,384 KB
testcase_25 AC 127 ms
30,436 KB
testcase_26 AC 126 ms
30,460 KB
testcase_27 AC 124 ms
32,116 KB
testcase_28 AC 124 ms
30,580 KB
testcase_29 AC 123 ms
30,396 KB
testcase_30 AC 127 ms
30,552 KB
testcase_31 AC 125 ms
30,456 KB
testcase_32 AC 128 ms
30,356 KB
testcase_33 AC 126 ms
30,584 KB
testcase_34 AC 126 ms
30,440 KB
testcase_35 AC 119 ms
29,980 KB
testcase_36 AC 118 ms
29,900 KB
testcase_37 AC 123 ms
30,036 KB
testcase_38 AC 120 ms
29,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


import numpy as np
n,m = list(map(int, input().split()))
c = list(map(int, input().split()))
c.insert(0,0)
c.append(0)
a = [[0]*n for _ in range(n)]
b = c[:]
for i in range(n):
    for j in range(1,m+1):
        if i+j<n:
            a[i][i+j] += 1/m
        else:
            a[i][n-1-(j-(n-1-i))] += 1/m
    a[i][i] -= 1
a = np.array(a)[:-1, :-1]
x = np.linalg.solve(a, -np.array(b[:-1])).tolist()
x.append(0)
inf = float("inf")
dp = [inf]*n
for i in range(n-m-1, n):
    dp[i] = c[i]
# print(dp)
for i in range(n-m-1)[::-1]:
    for j in range(1,m+1):
        dp[i] = min(dp[i], x[i+j]+c[i])
#     print(sum(dp[(i+1):(i+m+1)]), i+1, i+m)
    dp[i] = min(dp[i], sum(dp[i+1:i+m+1])/m + c[i])
ans = dp[0]
print(ans)
0