結果

問題 No.1818 6 Operations
ユーザー ForestedForested
提出日時 2021-11-08 21:53:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,557 ms / 2,500 ms
コード長 695 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 189,568 KB
最終ジャッジ日時 2024-04-28 23:40:11
合計ジャッジ時間 29,311 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,840 KB
testcase_01 AC 46 ms
57,344 KB
testcase_02 AC 48 ms
58,880 KB
testcase_03 AC 41 ms
51,968 KB
testcase_04 AC 41 ms
51,968 KB
testcase_05 AC 42 ms
51,968 KB
testcase_06 AC 42 ms
51,968 KB
testcase_07 AC 43 ms
51,712 KB
testcase_08 AC 524 ms
109,824 KB
testcase_09 AC 974 ms
141,440 KB
testcase_10 AC 493 ms
110,336 KB
testcase_11 AC 490 ms
107,648 KB
testcase_12 AC 749 ms
127,360 KB
testcase_13 AC 631 ms
117,888 KB
testcase_14 AC 723 ms
124,800 KB
testcase_15 AC 819 ms
132,352 KB
testcase_16 AC 672 ms
122,880 KB
testcase_17 AC 1,068 ms
146,048 KB
testcase_18 AC 1,356 ms
173,824 KB
testcase_19 AC 1,215 ms
169,984 KB
testcase_20 AC 1,344 ms
175,488 KB
testcase_21 AC 1,382 ms
177,280 KB
testcase_22 AC 1,126 ms
162,688 KB
testcase_23 AC 1,489 ms
183,680 KB
testcase_24 AC 1,554 ms
165,504 KB
testcase_25 AC 1,557 ms
189,568 KB
testcase_26 AC 1,337 ms
167,552 KB
testcase_27 AC 1,470 ms
172,032 KB
testcase_28 AC 538 ms
110,464 KB
testcase_29 AC 533 ms
108,160 KB
testcase_30 AC 1,353 ms
174,080 KB
testcase_31 AC 1,396 ms
180,096 KB
testcase_32 AC 1,513 ms
185,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def edit_distance(a, b):
    dp = [[0 for j in range(len(b) + 1)] for i in range(len(a) + 1)]
    for i in range(len(a) + 1):
        dp[i][0] = i
    for i in range(len(b) + 1):
        dp[0][i] = i
    for i in range(len(a)):
        for j in range(len(b)):
            dp[i + 1][j + 1] = min([dp[i + 1][j] + 1, dp[i][j] + (a[i] != b[j]), dp[i][j + 1] + 1])
    return dp[len(a)][len(b)]

n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = []
for i in range(n):
    aa += [0] * a[i]
    if i != n - 1:
        aa += [1]
bb = []
for i in range(m):
    bb += [0] * b[i]
    if i != m - 1:
        bb += [1]
print(edit_distance(aa, bb))
0