結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
68,144 KB
testcase_01 AC 70 ms
70,712 KB
testcase_02 AC 65 ms
68,144 KB
testcase_03 AC 63 ms
68,144 KB
testcase_04 AC 63 ms
68,144 KB
testcase_05 AC 62 ms
68,144 KB
testcase_06 AC 66 ms
68,144 KB
testcase_07 AC 62 ms
68,144 KB
testcase_08 AC 202 ms
106,164 KB
testcase_09 AC 259 ms
127,868 KB
testcase_10 AC 198 ms
106,488 KB
testcase_11 AC 199 ms
106,376 KB
testcase_12 AC 281 ms
128,676 KB
testcase_13 AC 164 ms
106,424 KB
testcase_14 AC 273 ms
126,620 KB
testcase_15 AC 229 ms
128,164 KB
testcase_16 AC 219 ms
124,620 KB
testcase_17 AC 341 ms
147,720 KB
testcase_18 AC 370 ms
172,600 KB
testcase_19 AC 338 ms
171,776 KB
testcase_20 AC 359 ms
173,652 KB
testcase_21 AC 371 ms
172,948 KB
testcase_22 AC 373 ms
151,132 KB
testcase_23 AC 387 ms
173,432 KB
testcase_24 AC 413 ms
167,600 KB
testcase_25 AC 385 ms
191,336 KB
testcase_26 AC 415 ms
169,424 KB
testcase_27 AC 439 ms
172,508 KB
testcase_28 AC 222 ms
104,732 KB
testcase_29 AC 202 ms
105,588 KB
testcase_30 AC 455 ms
172,664 KB
testcase_31 AC 433 ms
173,644 KB
testcase_32 AC 467 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:
        for _ in range(v):
            sb1.append(1)
        sb1.append(0)
    for v in nums2:
        for _ in range(v):
            sb2.append(1)
        sb2.append(0)

    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