結果

問題 No.225 文字列変更(medium)
ユーザー YutaroYamanakaYutaroYamanaka
提出日時 2019-05-31 16:26:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 769 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 65,444 KB
実行使用メモリ 7,748 KB
最終ジャッジ日時 2023-10-17 19:00:12
合計ジャッジ時間 1,561 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
7,708 KB
testcase_01 AC 16 ms
7,724 KB
testcase_02 AC 4 ms
7,548 KB
testcase_03 AC 4 ms
7,548 KB
testcase_04 AC 4 ms
7,600 KB
testcase_05 AC 4 ms
7,548 KB
testcase_06 AC 4 ms
7,600 KB
testcase_07 AC 4 ms
7,600 KB
testcase_08 AC 4 ms
7,600 KB
testcase_09 AC 4 ms
7,600 KB
testcase_10 AC 4 ms
7,600 KB
testcase_11 AC 4 ms
7,600 KB
testcase_12 AC 20 ms
7,732 KB
testcase_13 AC 22 ms
7,748 KB
testcase_14 AC 22 ms
7,740 KB
testcase_15 AC 12 ms
7,704 KB
testcase_16 AC 21 ms
7,740 KB
testcase_17 AC 13 ms
7,704 KB
testcase_18 AC 17 ms
7,716 KB
testcase_19 AC 21 ms
7,740 KB
testcase_20 AC 18 ms
7,720 KB
testcase_21 AC 21 ms
7,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int N, M;
string S, T;
int dp[1005][1005];
static const int INF = 10000000;

int min(int x, int y, int z) 
{ 
    return min(min(x, y), z); 
} 

int rec(int i, int j){
    if(dp[i][j] != INF) return dp[i][j];
    if(i < 0 || j < 0) return 0;
    if(i == 0 && j == 0) return 0;
    if(i == 0 && j > 0) return j;
    if(j == 0 && i > 0) return i;

    int ret = INF;
    if(S[i-1] == T[j-1]) ret = rec(i-1, j-1);
    else {
       ret = 1 + min(rec(i-1, j-1), rec(i, j-1), rec(i-1, j));
    }
    return dp[i][j] = ret;
}

int main(void){
    for(int i = 0; i <= 1004; i++) for(int j = 0; j <= 1004; j++) dp[i][j] = INF;
    
    cin >> N >> M;
    cin >> S >> T;
    cout << rec(S.size(), T.size()) << endl;
}
0