結果

問題 No.1818 6 Operations
ユーザー rin204rin204
提出日時 2022-01-23 02:08:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 619 ms / 2,500 ms
コード長 575 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 182,656 KB
最終ジャッジ日時 2024-05-06 09:33:26
合計ジャッジ時間 11,661 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,352 KB
testcase_01 AC 44 ms
59,008 KB
testcase_02 AC 40 ms
52,352 KB
testcase_03 AC 38 ms
51,968 KB
testcase_04 AC 35 ms
51,840 KB
testcase_05 AC 35 ms
52,096 KB
testcase_06 AC 38 ms
51,968 KB
testcase_07 AC 39 ms
51,968 KB
testcase_08 AC 231 ms
110,336 KB
testcase_09 AC 358 ms
136,960 KB
testcase_10 AC 217 ms
110,580 KB
testcase_11 AC 226 ms
107,648 KB
testcase_12 AC 327 ms
127,744 KB
testcase_13 AC 210 ms
114,944 KB
testcase_14 AC 279 ms
113,664 KB
testcase_15 AC 322 ms
132,992 KB
testcase_16 AC 246 ms
114,048 KB
testcase_17 AC 399 ms
136,576 KB
testcase_18 AC 570 ms
174,336 KB
testcase_19 AC 467 ms
159,872 KB
testcase_20 AC 528 ms
176,096 KB
testcase_21 AC 526 ms
177,280 KB
testcase_22 AC 483 ms
160,128 KB
testcase_23 AC 544 ms
182,656 KB
testcase_24 AC 483 ms
159,872 KB
testcase_25 AC 532 ms
182,400 KB
testcase_26 AC 493 ms
159,872 KB
testcase_27 AC 525 ms
172,232 KB
testcase_28 AC 248 ms
110,720 KB
testcase_29 AC 227 ms
108,160 KB
testcase_30 AC 563 ms
173,824 KB
testcase_31 AC 531 ms
180,352 KB
testcase_32 AC 619 ms
182,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
S = []
for a in A:
    S += [0] + [1] * a
T = []
for b in B:
    T += [0] + [1] * b
ls = len(S)
lt = len(T)
dp = [[1 << 30] * (lt + 1) for _ in range(ls + 1)]
dp[0][0] = 0

for i in range(1, ls + 1):
    for j in range(1, lt + 1):
        dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1)
        if S[i - 1] == T[j - 1]:
            dp[i][j] = min(dp[i][j], dp[i - 1][j - 1])
        else:
            dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1)

print(dp[ls][lt])
0