結果

問題 No.225 文字列変更(medium)
ユーザー ふーらくたるふーらくたる
提出日時 2016-09-23 18:18:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 814 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 53,328 KB
実行使用メモリ 7,628 KB
最終ジャッジ日時 2023-08-26 00:41:03
合計ジャッジ時間 1,440 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,436 KB
testcase_01 AC 6 ms
7,364 KB
testcase_02 AC 4 ms
7,340 KB
testcase_03 AC 4 ms
7,568 KB
testcase_04 AC 5 ms
7,340 KB
testcase_05 AC 4 ms
7,372 KB
testcase_06 AC 4 ms
7,560 KB
testcase_07 AC 4 ms
7,324 KB
testcase_08 AC 4 ms
7,288 KB
testcase_09 AC 4 ms
7,332 KB
testcase_10 AC 4 ms
7,344 KB
testcase_11 AC 4 ms
7,340 KB
testcase_12 AC 7 ms
7,628 KB
testcase_13 AC 7 ms
7,408 KB
testcase_14 AC 7 ms
7,340 KB
testcase_15 AC 7 ms
7,384 KB
testcase_16 AC 6 ms
7,376 KB
testcase_17 AC 7 ms
7,296 KB
testcase_18 AC 7 ms
7,340 KB
testcase_19 AC 6 ms
7,524 KB
testcase_20 AC 7 ms
7,328 KB
testcase_21 AC 7 ms
7,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

const int MAX_N = 1010;
const int MAX_M = 1010;

const int INF = (1 << 28);

int dp[MAX_N][MAX_M];

int main() {
    int n, m;
    string s, t;
    cin >> n >> m;
    cin >> s >> t;

    fill((int* )dp, (int* )(dp + MAX_N), INF);
    dp[0][0] = 0; dp[n][0] = n; dp[0][m] = m;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i - 1 >= 0) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
            }
            if (j - 1 >= 0) {
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
            }
            if (i - 1 >= 0 && j - 1 >= 0) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (s[i - 1] == t[j - 1] ? 0 : 1));
            }
        }
    }

    cout << dp[n][m] << endl;
    return 0;
}
0