結果

問題 No.225 文字列変更(medium)
ユーザー aruba1112aruba1112
提出日時 2021-08-17 11:28:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 834 bytes
コンパイル時間 1,931 ms
コンパイル使用メモリ 168,212 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-18 14:55:07
合計ジャッジ時間 2,532 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,816 KB
testcase_01 AC 9 ms
8,320 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 1 ms
6,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 13 ms
10,112 KB
testcase_13 WA -
testcase_14 AC 13 ms
10,624 KB
testcase_15 AC 13 ms
10,240 KB
testcase_16 AC 13 ms
10,240 KB
testcase_17 AC 12 ms
10,240 KB
testcase_18 AC 12 ms
9,984 KB
testcase_19 AC 12 ms
10,240 KB
testcase_20 WA -
testcase_21 AC 12 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));
    dp[0][0] = 0;

    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