結果

問題 No.225 文字列変更(medium)
ユーザー pekempeypekempey
提出日時 2015-06-12 22:29:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 1,167 ms
コンパイル使用メモリ 146,028 KB
実行使用メモリ 7,412 KB
最終ジャッジ日時 2023-09-20 21:06:19
合計ジャッジ時間 2,244 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
7,168 KB
testcase_14 WA -
testcase_15 AC 6 ms
7,088 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 7 ms
6,972 KB
testcase_21 AC 7 ms
7,172 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] == t[j]) {
                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