結果

問題 No.1818 6 Operations
ユーザー 👑 tamatotamato
提出日時 2022-01-21 22:14:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,015 ms / 2,500 ms
コード長 1,018 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 87,764 KB
実行使用メモリ 191,124 KB
最終ジャッジ日時 2023-08-17 06:22:16
合計ジャッジ時間 19,761 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,512 KB
testcase_01 AC 78 ms
75,952 KB
testcase_02 AC 73 ms
71,568 KB
testcase_03 AC 74 ms
71,828 KB
testcase_04 AC 71 ms
71,608 KB
testcase_05 AC 73 ms
71,756 KB
testcase_06 AC 73 ms
71,852 KB
testcase_07 AC 73 ms
71,872 KB
testcase_08 AC 372 ms
111,548 KB
testcase_09 AC 640 ms
142,968 KB
testcase_10 AC 281 ms
111,600 KB
testcase_11 AC 342 ms
109,192 KB
testcase_12 AC 539 ms
129,092 KB
testcase_13 AC 317 ms
119,496 KB
testcase_14 AC 542 ms
126,372 KB
testcase_15 AC 533 ms
133,988 KB
testcase_16 AC 475 ms
124,272 KB
testcase_17 AC 644 ms
147,276 KB
testcase_18 AC 917 ms
175,824 KB
testcase_19 AC 842 ms
171,900 KB
testcase_20 AC 887 ms
177,096 KB
testcase_21 AC 986 ms
179,072 KB
testcase_22 AC 717 ms
164,744 KB
testcase_23 AC 977 ms
184,892 KB
testcase_24 AC 855 ms
167,704 KB
testcase_25 AC 965 ms
191,124 KB
testcase_26 AC 796 ms
169,564 KB
testcase_27 AC 836 ms
173,672 KB
testcase_28 AC 424 ms
111,784 KB
testcase_29 AC 391 ms
109,576 KB
testcase_30 AC 980 ms
175,476 KB
testcase_31 AC 878 ms
181,796 KB
testcase_32 AC 1,015 ms
186,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9
inf = 10 ** 17


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    AA = []
    BB = []
    for a in A:
        for _ in range(a):
            AA.append(0)
        AA.append(1)
    for b in B:
        for _ in range(b):
            BB.append(0)
        BB.append(1)
    AA.pop()
    BB.pop()

    NN = len(AA)
    MM = len(BB)
    dp = [[inf] * (MM+1) for _ in range(NN+1)]
    dp[0][0] = 0
    for i in range(NN + 1):
        for j in range(MM + 1):
            cost = 1
            if i > 0 and j > 0:
                if AA[i-1] == BB[j-1]:
                    cost = 0
            if i > 0 and j > 0:
                dp[i][j] = min(dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + cost)
            elif i == 0:
                dp[i][j] = j
            elif j == 0:
                dp[i][j] = i
    print(dp[-1][-1])


if __name__ == '__main__':
    main()
0