結果

問題 No.225 文字列変更(medium)
ユーザー maine_honzukimaine_honzuki
提出日時 2020-12-25 11:34:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 631 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 207,508 KB
実行使用メモリ 7,540 KB
最終ジャッジ日時 2023-10-22 03:08:24
合計ジャッジ時間 2,996 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
5,232 KB
testcase_01 AC 13 ms
6,292 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
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 17 ms
7,240 KB
testcase_13 WA -
testcase_14 AC 17 ms
7,436 KB
testcase_15 AC 17 ms
7,268 KB
testcase_16 AC 17 ms
7,316 KB
testcase_17 AC 17 ms
7,288 KB
testcase_18 AC 16 ms
7,168 KB
testcase_19 AC 17 ms
7,292 KB
testcase_20 WA -
testcase_21 AC 16 ms
7,284 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 == -1 && t == -1)
        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] != T[t]));
    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);
    for (int i = 0; i < N; i++)
        memo[i].resize(M, -1);
    cout << book(N - 1, M - 1) << endl;
}
0