結果

問題 No.225 文字列変更(medium)
ユーザー machymachy
提出日時 2015-06-12 22:52:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 864 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 78,516 KB
実行使用メモリ 7,156 KB
最終ジャッジ日時 2023-08-25 22:44:21
合計ジャッジ時間 1,636 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,848 KB
testcase_01 AC 5 ms
5,844 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 7 ms
6,860 KB
testcase_13 AC 7 ms
7,156 KB
testcase_14 AC 7 ms
7,056 KB
testcase_15 AC 6 ms
7,124 KB
testcase_16 AC 6 ms
6,960 KB
testcase_17 AC 7 ms
6,924 KB
testcase_18 AC 6 ms
6,728 KB
testcase_19 AC 6 ms
6,852 KB
testcase_20 AC 6 ms
6,712 KB
testcase_21 AC 6 ms
6,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
typedef long long LL;


int main(){
    int sn, tn;
    string s, t;
    cin >> sn >> tn;
    cin >> s >> t;
    vector<vector<int> >  ed(sn+1, vector<int>(tn+1, sn*tn));
    for(int y = 0; y <= sn; y++){
        ed[y][0] = y;
    }
    for(int x = 0; x <= tn; x++){
        ed[0][x] = x;
    }
    for(int y = 1; y <= sn; y++){
        for(int x = 1; x <= tn; x++){
            if(s[y-1] == t[x-1]){
                ed[y][x] = min(ed[y][x], ed[y-1][x-1]);
            }else{
                ed[y][x] = min(ed[y][x], ed[y-1][x-1]+1);
            }
            ed[y][x] = min(ed[y][x], ed[y-1][x]+1);
            ed[y][x] = min(ed[y][x], ed[y][x-1]+1);
        }
    }
    cout << ed[sn][tn] << endl;
    return 0;
}
0