結果

問題 No.225 文字列変更(medium)
ユーザー machy
提出日時 2015-06-12 22:52:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 864 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 79,756 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-12-24 10:08:27
合計ジャッジ時間 1,477 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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