結果

問題 No.2566 美しい整数列
ユーザー oginoshikibuoginoshikibu
提出日時 2023-12-02 16:38:39
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,024 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 55,600 KB
最終ジャッジ日時 2023-12-02 16:38:45
合計ジャッジ時間 5,028 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
55,600 KB
testcase_01 AC 36 ms
55,600 KB
testcase_02 AC 35 ms
55,600 KB
testcase_03 AC 35 ms
55,600 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque
from itertools import accumulate

n,m=map(int, input().split())
A=list(map(int, input().split()))
B=tuple(map(int, input().split()))
C=tuple(map(int, input().split()))
CA=list(accumulate(C))

if n==2:
    print(min(C[0] if A[1]-A[0]!=B[0] else 0,C[1] if A[1]-A[0]!=B[0] else 0))
    exit()

INF=float("inf")

S=defaultdict(lambda: INF)
if A[1]-A[0]==B[0]:
    S[A[1]]=min(S[A[1]],0)
else:
    S[A[1]]=min(S[A[1]],C[0])
    S[A[0]+B[0]]=min(S[A[0]+B[0]],C[1])

ans=INF

for idx in range(2,n):
    cmin=INF
    newS=defaultdict(lambda: INF)
    # print(dict(S))
    for prev,cost in S.items():
        cmin=min(cmin,cost)
        if idx==n-1:
            ans=min(ans,cost+C[-1] if prev+B[(idx-1)%m]!=A[idx] else cost)
            continue
        if prev+B[(idx-1)%m]==A[idx]:
            newS[A[idx]]=min(newS[A[idx]],cost)
        else:
            newS[prev+B[(idx-1)%m]]=min(newS[prev+B[(idx-1)%m]],cost+C[idx])
    newS[A[idx]]=min(newS[A[idx]],CA[idx-1])
    S=newS

print(ans)
0