結果

問題 No.2566 美しい整数列
ユーザー hirayuu_ychirayuu_yc
提出日時 2023-12-02 14:47:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 517 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 172,224 KB
最終ジャッジ日時 2023-12-02 14:47:16
合計ジャッジ時間 6,646 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
55,604 KB
testcase_01 AC 35 ms
55,604 KB
testcase_02 AC 36 ms
55,604 KB
testcase_03 AC 35 ms
55,604 KB
testcase_04 AC 224 ms
172,224 KB
testcase_05 AC 220 ms
166,312 KB
testcase_06 AC 175 ms
141,012 KB
testcase_07 AC 162 ms
137,292 KB
testcase_08 AC 174 ms
139,132 KB
testcase_09 AC 168 ms
137,892 KB
testcase_10 AC 170 ms
138,020 KB
testcase_11 AC 196 ms
140,732 KB
testcase_12 AC 202 ms
141,636 KB
testcase_13 AC 188 ms
140,592 KB
testcase_14 AC 181 ms
141,096 KB
testcase_15 AC 178 ms
141,080 KB
testcase_16 AC 199 ms
161,832 KB
testcase_17 AC 203 ms
164,056 KB
testcase_18 AC 210 ms
164,660 KB
testcase_19 AC 146 ms
123,720 KB
testcase_20 AC 193 ms
160,080 KB
testcase_21 AC 218 ms
163,012 KB
testcase_22 AC 149 ms
132,784 KB
testcase_23 AC 177 ms
137,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
cum=[0]
for i in C:
    cum.append(cum[-1]+i)
before=defaultdict(lambda:-1)
before[A[0]]=0
ans=[0]*(N+1)
neg=0
for i in range(N-1):
    neg+=B[i%M]
    ans[i+1]=ans[before[A[i+1]-neg]]+cum[i+1]-cum[before[A[i+1]-neg]+1]
    before[A[i+1]-neg]=max(before[A[i+1]-neg],i+1)
fin=ans[-2]
for i in range(N):
    fin=min(fin,ans[i]+cum[-1]-cum[i+1])
print(fin)
0