結果

問題 No.225 文字列変更(medium)
ユーザー pekempeypekempey
提出日時 2015-06-12 22:35:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 897 bytes
コンパイル時間 1,152 ms
コンパイル使用メモリ 145,924 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2023-08-25 22:43:08
合計ジャッジ時間 2,032 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,824 KB
testcase_01 AC 5 ms
7,324 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 6 ms
6,964 KB
testcase_13 AC 6 ms
7,176 KB
testcase_14 AC 6 ms
7,152 KB
testcase_15 AC 6 ms
6,988 KB
testcase_16 AC 6 ms
7,188 KB
testcase_17 AC 6 ms
6,936 KB
testcase_18 AC 5 ms
6,944 KB
testcase_19 AC 5 ms
7,072 KB
testcase_20 AC 6 ms
6,916 KB
testcase_21 AC 6 ms
7,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

int dp[1001][1001];

int levenshteinDisntace(string s, string t) {
    rep (i, s.length() + 1) {
        dp[i][0] = i;
    }

    rep (i, t.length() + 1) {
        dp[0][i] = i;
    }

    rep2 (i, 1, s.length() + 1) {
        rep2 (j, 1, t.length() + 1) {
            int cost;

            if (s[i - 1] == t[j - 1]) {
                cost = 0;
            } else {
                cost = 1;
            }

            dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost});
        }
    }

    return dp[s.length()][t.length()];
}


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

    cout << levenshteinDisntace(s, t) << endl;
}
0