結果

問題 No.225 文字列変更(medium)
ユーザー ミドリムシミドリムシ
提出日時 2018-06-12 16:56:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 751 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 70,196 KB
実行使用メモリ 7,708 KB
最終ジャッジ日時 2023-09-13 03:39:13
合計ジャッジ時間 1,901 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
7,708 KB
testcase_01 AC 13 ms
7,408 KB
testcase_02 AC 4 ms
7,328 KB
testcase_03 AC 4 ms
7,612 KB
testcase_04 AC 5 ms
7,432 KB
testcase_05 AC 4 ms
7,560 KB
testcase_06 AC 4 ms
7,336 KB
testcase_07 AC 4 ms
7,560 KB
testcase_08 AC 4 ms
7,336 KB
testcase_09 AC 5 ms
7,556 KB
testcase_10 AC 5 ms
7,528 KB
testcase_11 AC 5 ms
7,316 KB
testcase_12 AC 16 ms
7,540 KB
testcase_13 AC 20 ms
7,412 KB
testcase_14 AC 17 ms
7,420 KB
testcase_15 AC 11 ms
7,576 KB
testcase_16 AC 18 ms
7,572 KB
testcase_17 AC 11 ms
7,332 KB
testcase_18 AC 15 ms
7,344 KB
testcase_19 AC 16 ms
7,356 KB
testcase_20 AC 15 ms
7,584 KB
testcase_21 AC 16 ms
7,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;

int n, m;
string S, T;

int dp[1010][1010];

int choose(int s_now, int t_now){
    if(dp[s_now][t_now] != -1){
        return dp[s_now][t_now];
    }else if(s_now == n){
        return dp[s_now][t_now] = m - t_now;
    }else if(t_now == m){
        return dp[s_now][t_now] = n - s_now;
    }else if(S[s_now] == T[t_now]){
        return dp[s_now][t_now] = choose(s_now + 1, t_now + 1);
    }else{
        return dp[s_now][t_now] = min({choose(s_now, t_now + 1) + 1, choose(s_now + 1, t_now) + 1, choose(s_now + 1, t_now + 1) + 1});
    }
}

int main(){
    cin >> n >> m >> S >> T;
    memset(dp, -1, sizeof(dp));
    cout << choose(0, 0) << endl;
}
0