結果

問題 No.225 文字列変更(medium)
ユーザー aruba1112aruba1112
提出日時 2021-08-17 11:49:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 890 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 169,648 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-18 15:11:22
合計ジャッジ時間 2,641 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,816 KB
testcase_01 AC 9 ms
8,320 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 14 ms
10,240 KB
testcase_13 AC 14 ms
10,880 KB
testcase_14 AC 14 ms
10,624 KB
testcase_15 AC 15 ms
10,368 KB
testcase_16 AC 14 ms
10,496 KB
testcase_17 AC 15 ms
10,240 KB
testcase_18 AC 15 ms
10,112 KB
testcase_19 AC 13 ms
10,496 KB
testcase_20 AC 14 ms
9,856 KB
testcase_21 AC 13 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
using ll = long long;
const ll INF = 1LL<<60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}

int main() {
    int n, m; cin >> n >> m;
    string S, T; cin >> S >> T;

    vector<vector<ll>> dp(S.size()+1, vector<ll>(T.size()+1, INF));
    rep(i, S.size()+1) dp[i][0] = i;
    rep(i, T.size()+1) dp[0][i] = i;

    rep(i, S.size()) rep(j, T.size()) {
        if (S[i] == T[j]) chmin(dp[i+1][j+1], dp[i][j]); // copy
        chmin(dp[i+1][j+1], dp[i][j] + 1); // replace
        chmin(dp[i+1][j+1], dp[i][j+1] + 1); // delete
        chmin(dp[i+1][j+1], dp[i+1][j] + 1); // insert
    }

    cout << dp[S.size()][T.size()] << endl;

    return 0;
}
0