結果

問題 No.225 文字列変更(medium)
ユーザー fine
提出日時 2016-04-05 00:35:32
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 629 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 58,464 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-12-24 10:49:25
合計ジャッジ時間 1,448 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
typedef long long ll;
 
int main() {
    int dp[1001][1001], l1, l2, cost;
    string s1, s2;
    cin >> l1 >> l2;
    cin >> s1;
    cin >> s2;
    for(int i = 0; i <= l1; i++) dp[i][0] = i;
    for(int i = 0; i <= l2; i++) dp[0][i] = i;
    for(int i = 1; i <= l1; i++) {
        for(int j = 1; j <= l2; j++) {
            if (s1[i - 1] == s2[j - 1]) cost = 0;
            else cost = 1;
            dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost));
        }
    }
    cout << dp[l1][l2] << endl;
    return 0;
}
0