結果

問題 No.225 文字列変更(medium)
ユーザー face4face4
提出日時 2018-10-14 18:28:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 601 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 66,160 KB
実行使用メモリ 7,204 KB
最終ジャッジ日時 2024-04-20 20:18:15
合計ジャッジ時間 1,344 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
6,144 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 5 ms
6,912 KB
testcase_13 AC 5 ms
7,168 KB
testcase_14 AC 4 ms
7,204 KB
testcase_15 AC 5 ms
6,912 KB
testcase_16 AC 5 ms
7,040 KB
testcase_17 AC 5 ms
7,040 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 4 ms
7,088 KB
testcase_20 AC 4 ms
6,784 KB
testcase_21 AC 4 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int LevenDis(string a, string b){
    int alen = a.length(), blen = b.length();
    int dp[alen+1][blen+1];

    for(int i = 0; i < alen+1; i++) dp[i][0] = i;
    for(int j = 0; j < blen+1; j++) dp[0][j] = j;

    for(int i = 1; i < alen+1; i++){
        for(int j = 1; j < blen+1; j++){
            dp[i][j] = min(dp[i-1][j]+1, min(dp[i][j-1]+1, dp[i-1][j-1] + (a[i-1] != b[j-1])));
        }
    }

    return dp[alen][blen];
}

int main(){
    int n, m;
    string s, t;

    cin >> n >> m >> s >> t;

    cout << LevenDis(s,t) << endl;
    
    return 0;
}
0