結果

問題 No.225 文字列変更(medium)
ユーザー tottoripapertottoripaper
提出日時 2015-06-13 20:47:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 483 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 59,548 KB
実行使用メモリ 7,476 KB
最終ジャッジ日時 2023-08-25 22:47:48
合計ジャッジ時間 1,435 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,948 KB
testcase_01 AC 6 ms
7,476 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 6 ms
6,868 KB
testcase_13 AC 7 ms
7,112 KB
testcase_14 AC 7 ms
7,116 KB
testcase_15 AC 6 ms
7,180 KB
testcase_16 AC 7 ms
7,264 KB
testcase_17 AC 6 ms
6,936 KB
testcase_18 AC 6 ms
6,816 KB
testcase_19 AC 6 ms
7,052 KB
testcase_20 AC 6 ms
6,912 KB
testcase_21 AC 6 ms
6,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

int N, M;
std::string S, T;
int dp[1001][1001];

int main(){
    std::cin >> N >> M;
    std::cin >> S >> T;

    for(int i=1;i<=N;i++){
        dp[i][0] = i;
    }

    for(int i=1;i<=M;i++){
        dp[0][i] = i;
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            dp[i][j] = std::min({dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + (S[i-1] != T[j-1])});
        }
    }

    std::cout << dp[N][M] << std::endl;
}
0