結果

問題 No.225 文字列変更(medium)
ユーザー kuc_jacksonkuc_jackson
提出日時 2021-05-02 13:46:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 656 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 203,536 KB
実行使用メモリ 7,156 KB
最終ジャッジ日時 2023-09-28 03:50:06
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,856 KB
testcase_01 AC 5 ms
6,064 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 6 ms
6,932 KB
testcase_13 AC 6 ms
7,156 KB
testcase_14 AC 5 ms
7,060 KB
testcase_15 AC 6 ms
6,848 KB
testcase_16 AC 6 ms
7,000 KB
testcase_17 AC 6 ms
6,956 KB
testcase_18 AC 5 ms
6,744 KB
testcase_19 AC 5 ms
7,072 KB
testcase_20 AC 5 ms
6,736 KB
testcase_21 AC 5 ms
6,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
template<typename T> inline bool chmax(T &a, const T &b){if(a < b){a = b; return true;}return false;}
using namespace std;
using ll = long long;

ll INF = 1e8;

int main(){
    int N, M; cin >> N >> M;
    string S, T; cin >> S >> T;
    vector<vector<int>> dp(N + 1, vector<int>(M + 1, INF));
    dp[0][0] = 0;
    for(int i = 0; i < N; i++)dp[i + 1][0] = dp[i][0] + 1;
    for(int i = 0; i < M; i++)dp[0][i + 1] = dp[0][i] + 1;
    for(int i = 0; i < N; i++)for(int j = 0; j < M; j++){
        dp[i + 1][j + 1] = min(dp[i][j] + (S[i] == T[j] ? 0: 1), min(dp[i][j + 1] + 1, dp[i + 1][j] + 1));
    }
    cout << dp[N][M] << endl;
}
0