結果

問題 No.2603 Tone Correction
ユーザー ニックネームニックネーム
提出日時 2024-01-13 01:39:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 711 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 437,024 KB
最終ジャッジ日時 2024-01-13 01:39:53
合計ジャッジ時間 31,305 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,332 KB
testcase_01 AC 34 ms
53,332 KB
testcase_02 AC 46 ms
53,332 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 35 ms
53,332 KB
testcase_34 AC 1,014 ms
435,824 KB
testcase_35 AC 1,018 ms
435,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
u = [0]*(n+1); d = [0]*(n+1); k = 100
for i,(x,y) in enumerate(zip(a,b),1): u[i] = (y-x)%m; d[i] = (x-y)%m
dpu = [list(range(0,m*k,m))]+[[0]*k for i in range(n)]
dpd = [list(range(0,m*k,m))]+[[0]*k for i in range(n)]
for i in range(n):
    for j in range(1,k):
        dpu[i+1][j] = min(dpu[i][j]+max(u[i+1]-u[i],0),dpu[i][j-1]+u[i+1]+m-u[i])
        dpd[i+1][j] = min(dpd[i][j]+max(d[i+1]-d[i],0),dpd[i][j-1]+d[i+1]+m-d[i])
    dpu[i+1][0] = min(dpu[i][0]+max(u[i+1]-u[i],0),dpd[i][0]+u[i+1],dpu[i][1])
    dpd[i+1][0] = min(dpd[i][0]+max(d[i+1]-d[i],0),dpu[i][0]+d[i+1],dpd[i][1])
print(min(*dpu[n],*dpd[n]))
0