結果

問題 No.1818 6 Operations
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-03-15 13:21:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 480 ms / 2,500 ms
コード長 1,203 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,692 KB
実行使用メモリ 191,428 KB
最終ジャッジ日時 2023-10-18 12:22:15
合計ジャッジ時間 10,527 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
68,144 KB
testcase_01 AC 72 ms
70,712 KB
testcase_02 AC 67 ms
68,144 KB
testcase_03 AC 65 ms
68,144 KB
testcase_04 AC 64 ms
68,144 KB
testcase_05 AC 68 ms
68,144 KB
testcase_06 AC 65 ms
68,144 KB
testcase_07 AC 64 ms
68,144 KB
testcase_08 AC 205 ms
106,180 KB
testcase_09 AC 312 ms
127,964 KB
testcase_10 AC 201 ms
106,528 KB
testcase_11 AC 202 ms
106,392 KB
testcase_12 AC 277 ms
128,680 KB
testcase_13 AC 220 ms
106,500 KB
testcase_14 AC 283 ms
126,624 KB
testcase_15 AC 297 ms
128,248 KB
testcase_16 AC 250 ms
124,708 KB
testcase_17 AC 339 ms
147,700 KB
testcase_18 AC 462 ms
172,724 KB
testcase_19 AC 411 ms
171,992 KB
testcase_20 AC 359 ms
173,652 KB
testcase_21 AC 460 ms
173,060 KB
testcase_22 AC 376 ms
151,136 KB
testcase_23 AC 465 ms
173,504 KB
testcase_24 AC 340 ms
167,524 KB
testcase_25 AC 480 ms
191,428 KB
testcase_26 AC 339 ms
169,340 KB
testcase_27 AC 440 ms
172,624 KB
testcase_28 AC 224 ms
104,760 KB
testcase_29 AC 204 ms
105,596 KB
testcase_30 AC 456 ms
172,692 KB
testcase_31 AC 431 ms
173,644 KB
testcase_32 AC 473 ms
173,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import Any, Sequence


INF = int(1e18)


def min(a: int, b: int) -> int:
    return a if a < b else b


def editDistance(word1: Sequence[Any], word2: Sequence[Any]) -> int:
    n1, n2 = len(word1), len(word2)
    dp = [[INF] * (n2 + 1) for _ in range(n1 + 1)]
    dp[0][0] = 0

    for i in range(n1 + 1):
        dp[i][0] = i
    for j in range(n2 + 1):
        dp[0][j] = j

    for i in range(1, n1 + 1):
        for j in range(1, n2 + 1):
            if word1[i - 1] == word2[j - 1]:
                dp[i][j] = dp[i - 1][j - 1]
            else:
                dp[i][j] = min(dp[i - 1][j - 1] + 1, min(dp[i - 1][j] + 1, dp[i][j - 1] + 1))

    return dp[n1][n2]

from typing import List


def operation6(nums1: List[int], nums2: List[int]) -> int:
    sb1, sb2 = [], []
    for v in nums1:
        sb1.append(0)
        for _ in range(v):
            sb1.append(1)
    for v in nums2:
        sb2.append(0)
        for _ in range(v):
            sb2.append(1)

    return editDistance(sb1, sb2)


if __name__ == "__main__":
    n, m = map(int, input().split())
    nums1 = list(map(int, input().split()))
    nums2 = list(map(int, input().split()))
    print(operation6(nums1, nums2))
0