結果

問題 No.225 文字列変更(medium)
ユーザー maine_honzukimaine_honzuki
提出日時 2020-12-25 11:38:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 640 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 207,644 KB
実行使用メモリ 7,528 KB
最終ジャッジ日時 2023-10-22 03:11:04
合計ジャッジ時間 3,434 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
5,228 KB
testcase_01 AC 12 ms
6,288 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 16 ms
7,244 KB
testcase_13 AC 17 ms
7,528 KB
testcase_14 AC 17 ms
7,428 KB
testcase_15 AC 16 ms
7,260 KB
testcase_16 AC 16 ms
7,324 KB
testcase_17 AC 16 ms
7,280 KB
testcase_18 AC 16 ms
7,160 KB
testcase_19 AC 17 ms
7,288 KB
testcase_20 AC 16 ms
7,096 KB
testcase_21 AC 17 ms
7,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N, M;
string S, T;

vector<vector<int>> memo;

int book(int s, int t) {
    if (s == 0 && t == 0)
        return 0;
    if (s < 0 || t < 0)
        return 1e5;
    if (memo[s][t] != -1)
        return memo[s][t];
    int& ret = memo[s][t];
    ret = 1e5;
    ret = min(ret, book(s - 1, t - 1) + (S[s - 1] != T[t - 1]));
    ret = min(ret, book(s - 1, t) + 1);
    ret = min(ret, book(s, t - 1) + 1);
    return ret;
}

int main() {
    cin >> N >> M >> S >> T;
    memo.resize(N + 1);
    for (int i = 0; i < N + 1; i++)
        memo[i].resize(M + 1, -1);
    cout << book(N, M) << endl;
}
0