結果

問題 No.225 文字列変更(medium)
ユーザー mamekinmamekin
提出日時 2015-08-01 10:41:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,174 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 92,540 KB
実行使用メモリ 6,748 KB
最終ジャッジ日時 2023-08-25 23:03:28
合計ジャッジ時間 1,721 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,592 KB
testcase_01 AC 6 ms
5,724 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 7 ms
6,540 KB
testcase_13 AC 7 ms
6,700 KB
testcase_14 AC 6 ms
6,748 KB
testcase_15 AC 6 ms
6,448 KB
testcase_16 AC 6 ms
6,448 KB
testcase_17 AC 6 ms
6,596 KB
testcase_18 AC 6 ms
6,596 KB
testcase_19 AC 7 ms
6,440 KB
testcase_20 AC 6 ms
6,580 KB
testcase_21 AC 6 ms
6,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int LevenshteinDist(const string& s, const string& t)
{
    int n = s.size();
    int m = t.size();
    vector<vector<int> > minCost(n+2, vector<int>(m+2, INT_MAX));
    minCost[0][0] = 0;
    for(int i=0; i<=n; ++i){
        for(int j=0; j<=m; ++j){
            minCost[i+1][j] = min(minCost[i+1][j], minCost[i][j] + 1);
            minCost[i][j+1] = min(minCost[i][j+1], minCost[i][j] + 1);
            if(i < n && j < m && s[i] == t[j])
                minCost[i+1][j+1] = min(minCost[i+1][j+1], minCost[i][j]);
            else
                minCost[i+1][j+1] = min(minCost[i+1][j+1], minCost[i][j] + 1);
        }
    }
    return minCost[n][m];
}

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

    cout << LevenshteinDist(s, t) << endl;

    return 0;
}
0