結果

問題 No.2603 Tone Correction
ユーザー ニックネームニックネーム
提出日時 2024-01-13 01:43:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 818 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 436,992 KB
最終ジャッジ日時 2024-01-13 01:43:59
合計ジャッジ時間 39,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,332 KB
testcase_01 AC 37 ms
53,332 KB
testcase_02 AC 43 ms
55,460 KB
testcase_03 AC 107 ms
81,376 KB
testcase_04 AC 107 ms
81,384 KB
testcase_05 AC 110 ms
81,512 KB
testcase_06 AC 107 ms
81,384 KB
testcase_07 AC 110 ms
81,384 KB
testcase_08 AC 108 ms
81,388 KB
testcase_09 AC 108 ms
81,516 KB
testcase_10 AC 108 ms
81,384 KB
testcase_11 AC 109 ms
81,388 KB
testcase_12 AC 109 ms
81,368 KB
testcase_13 AC 1,708 ms
436,988 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1,707 ms
436,968 KB
testcase_19 AC 1,699 ms
436,964 KB
testcase_20 WA -
testcase_21 AC 1,676 ms
436,960 KB
testcase_22 AC 1,670 ms
436,864 KB
testcase_23 WA -
testcase_24 AC 1,653 ms
436,920 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1,657 ms
436,924 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1,645 ms
436,920 KB
testcase_32 AC 1,675 ms
436,920 KB
testcase_33 AC 36 ms
53,332 KB
testcase_34 AC 1,323 ms
436,032 KB
testcase_35 AC 1,349 ms
436,032 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):
    dpu[i+1][0] = min(dpu[i][0]+max(u[i+1]-u[i],0),dpd[i][0]+u[i+1])
    dpd[i+1][0] = min(dpd[i][0]+max(d[i+1]-d[i],0),dpu[i][0]+d[i+1])
    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])
    for j in range(k-1):
        dpu[i+1][j] = min(dpu[i+1][j],dpu[i][j+1])
        dpd[i+1][j] = min(dpd[i+1][j],dpd[i][j+1])
print(min(*dpu[n],*dpd[n]))
0