結果
問題 |
No.225 文字列変更(medium)
|
ユーザー |
|
提出日時 | 2021-08-01 23:53:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 114 ms / 5,000 ms |
コード長 | 548 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 83,200 KB |
最終ジャッジ日時 | 2024-09-16 13:05:02 |
合計ジャッジ時間 | 2,896 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
N, M = map(int, input().split()) S = ' ' + input() T = ' ' + input() INF = 10**10 DP = [] for _ in range(N+1): DP.append([INF]*(M+1)) DP[0][0] = 0 for i in range(N+1): for j in range(M+1): if i > 0 and j > 0: if S[i] == T[j]: 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) if i > 0: DP[i][j] = min(DP[i-1][j] + 1, DP[i][j]) if j > 0: DP[i][j] = min(DP[i][j-1] + 1, DP[i][j]) print(DP[N][M])