結果

問題 No.225 文字列変更(medium)
ユーザー finefine
提出日時 2016-04-05 00:35:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 629 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 59,004 KB
実行使用メモリ 7,276 KB
最終ジャッジ日時 2023-08-25 23:06:47
合計ジャッジ時間 1,292 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,408 KB
testcase_01 AC 5 ms
7,260 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 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 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 5 ms
7,016 KB
testcase_13 AC 6 ms
7,276 KB
testcase_14 AC 5 ms
7,248 KB
testcase_15 AC 5 ms
7,076 KB
testcase_16 AC 5 ms
7,148 KB
testcase_17 AC 5 ms
6,976 KB
testcase_18 AC 4 ms
6,948 KB
testcase_19 AC 5 ms
7,164 KB
testcase_20 AC 5 ms
6,892 KB
testcase_21 AC 4 ms
7,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
typedef long long ll;
 
int main() {
    int dp[1001][1001], l1, l2, cost;
    string s1, s2;
    cin >> l1 >> l2;
    cin >> s1;
    cin >> s2;
    for(int i = 0; i <= l1; i++) dp[i][0] = i;
    for(int i = 0; i <= l2; i++) dp[0][i] = i;
    for(int i = 1; i <= l1; i++) {
        for(int j = 1; j <= l2; j++) {
            if (s1[i - 1] == s2[j - 1]) cost = 0;
            else cost = 1;
            dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost));
        }
    }
    cout << dp[l1][l2] << endl;
    return 0;
}
0