結果
問題 | No.225 文字列変更(medium) |
ユーザー | rpy3cpp |
提出日時 | 2015-06-13 14:26:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,286 ms / 5,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 334 ms |
コンパイル使用メモリ | 87,056 KB |
実行使用メモリ | 288,588 KB |
最終ジャッジ日時 | 2023-09-21 00:04:54 |
合計ジャッジ時間 | 14,944 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 580 ms
175,824 KB |
testcase_01 | AC | 980 ms
257,568 KB |
testcase_02 | AC | 73 ms
71,440 KB |
testcase_03 | AC | 72 ms
71,200 KB |
testcase_04 | AC | 71 ms
71,284 KB |
testcase_05 | AC | 72 ms
71,348 KB |
testcase_06 | AC | 73 ms
71,368 KB |
testcase_07 | AC | 73 ms
71,396 KB |
testcase_08 | AC | 75 ms
71,508 KB |
testcase_09 | AC | 73 ms
71,224 KB |
testcase_10 | AC | 73 ms
71,348 KB |
testcase_11 | AC | 73 ms
71,384 KB |
testcase_12 | AC | 1,084 ms
288,588 KB |
testcase_13 | AC | 1,283 ms
288,376 KB |
testcase_14 | AC | 1,286 ms
272,684 KB |
testcase_15 | AC | 534 ms
183,784 KB |
testcase_16 | AC | 1,280 ms
272,960 KB |
testcase_17 | AC | 572 ms
180,776 KB |
testcase_18 | AC | 1,280 ms
244,276 KB |
testcase_19 | AC | 1,244 ms
287,480 KB |
testcase_20 | AC | 852 ms
253,496 KB |
testcase_21 | AC | 1,211 ms
273,436 KB |
ソースコード
def read_data(): n, m = map(int, input().split()) S = input().strip() T = input().strip() return n, m, S, T memo = dict() def f(a, b, S, T): ''' f(a, b, S, T) S[:a] を T[:b] に変更するのに必要な最低ステップ数 ''' global memo if (a, b) in memo: return memo[a, b] if a == 0: return b if b == 0: return a s = S[a - 1] t = T[b - 1] if s == t: memo[a, b] = f(a-1, b-1, S, T) return memo[a, b] if s != t: steps_change = 1 + f(a-1, b-1, S, T) steps_insert = 1 + f(a, b-1, S, T) steps_delete = 1 + f(a-1, b, S, T) memo[a, b] = min(steps_change, steps_insert, steps_delete) return memo[a, b] if __name__ == '__main__': n, m, S, T = read_data() print(f(n, m, S, T))