結果

問題 No.225 文字列変更(medium)
ユーザー Manuel1024Manuel1024
提出日時 2020-12-14 02:30:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 969 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 72,888 KB
実行使用メモリ 7,460 KB
最終ジャッジ日時 2023-10-20 04:38:35
合計ジャッジ時間 1,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,156 KB
testcase_01 AC 7 ms
6,216 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 10 ms
7,176 KB
testcase_13 AC 10 ms
7,460 KB
testcase_14 AC 11 ms
7,360 KB
testcase_15 AC 10 ms
7,192 KB
testcase_16 AC 10 ms
7,252 KB
testcase_17 AC 11 ms
7,212 KB
testcase_18 AC 11 ms
7,092 KB
testcase_19 AC 10 ms
7,220 KB
testcase_20 AC 11 ms
7,024 KB
testcase_21 AC 10 ms
7,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s;
    cin >> t;
    vector<vector<int>> memo(n+1, vector<int>(m+1, 1001001001));
    memo[0][0] = 0;
    for(int i = 1; i <= n; i++) memo[i][0] = i;
    for(int j = 1; j <= m; j++) memo[0][j] = j;

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i > 0 && j > 0){
                if(memo[i][j] > memo[i-1][j-1] +
                ((s[i-1] == t[j-1]) ? 0 : 1)){
                    memo[i][j] = memo[i-1][j-1] +
                    ((s[i-1] == t[j-1]) ? 0 : 1);
                }
            }
            if(i > 0 && memo[i][j] > memo[i-1][j]+1){
                memo[i][j] = memo[i-1][j]+1;
            }
            if(j > 0 && memo[i][j] > memo[i][j-1]+1){
                memo[i][j] = memo[i][j-1]+1;
            }
        }
    }
    cout << memo[n][m] << endl;
    return 0;
}
0