結果

問題 No.1818 6 Operations
ユーザー mkawa2mkawa2
提出日時 2024-02-15 23:12:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 566 ms / 2,500 ms
コード長 1,222 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 181,996 KB
最終ジャッジ日時 2024-02-15 23:12:44
合計ジャッジ時間 11,441 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 46 ms
61,944 KB
testcase_02 AC 40 ms
58,932 KB
testcase_03 AC 35 ms
53,456 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 254 ms
109,984 KB
testcase_09 AC 371 ms
136,428 KB
testcase_10 AC 175 ms
110,112 KB
testcase_11 AC 219 ms
107,768 KB
testcase_12 AC 254 ms
127,520 KB
testcase_13 AC 205 ms
114,336 KB
testcase_14 AC 295 ms
124,652 KB
testcase_15 AC 266 ms
132,384 KB
testcase_16 AC 225 ms
123,116 KB
testcase_17 AC 423 ms
146,156 KB
testcase_18 AC 437 ms
174,060 KB
testcase_19 AC 380 ms
169,836 KB
testcase_20 AC 540 ms
175,596 KB
testcase_21 AC 445 ms
177,132 KB
testcase_22 AC 490 ms
159,468 KB
testcase_23 AC 439 ms
181,996 KB
testcase_24 AC 392 ms
159,340 KB
testcase_25 AC 451 ms
181,996 KB
testcase_26 AC 490 ms
167,916 KB
testcase_27 AC 424 ms
171,884 KB
testcase_28 AC 241 ms
110,716 KB
testcase_29 AC 183 ms
107,772 KB
testcase_30 AC 449 ms
173,676 KB
testcase_31 AC 549 ms
180,332 KB
testcase_32 AC 566 ms
181,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

n, m = LI()
aa = []
for a in LI(): aa += [1]*a+[0]
bb = []
for a in LI(): bb += [1]*a+[0]
n, m = len(aa), len(bb)

def chmin(i, j, val):
    if val < dp[i][j]: dp[i][j] = val

dp = [[inf]*(m+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n+1):
    for j in range(m+1):
        pre = dp[i][j]
        if i < n and j < m: chmin(i+1, j+1, pre+(aa[i] ^ bb[j]))
        if i < n: chmin(i+1, j, pre+1)
        if j < m: chmin(i, j+1, pre+1)

print(dp[n][m])
0