結果

問題 No.225 文字列変更(medium)
ユーザー imulanimulan
提出日時 2016-07-28 17:49:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 165,540 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-08-25 23:08:50
合計ジャッジ時間 2,476 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,272 KB
testcase_01 AC 6 ms
7,256 KB
testcase_02 AC 4 ms
7,452 KB
testcase_03 AC 4 ms
7,272 KB
testcase_04 AC 4 ms
7,252 KB
testcase_05 AC 4 ms
7,328 KB
testcase_06 AC 4 ms
7,444 KB
testcase_07 AC 3 ms
7,336 KB
testcase_08 AC 5 ms
7,252 KB
testcase_09 AC 3 ms
7,408 KB
testcase_10 AC 4 ms
7,340 KB
testcase_11 AC 4 ms
7,344 KB
testcase_12 AC 6 ms
7,264 KB
testcase_13 AC 6 ms
7,260 KB
testcase_14 AC 7 ms
7,296 KB
testcase_15 AC 7 ms
7,332 KB
testcase_16 AC 6 ms
7,564 KB
testcase_17 AC 7 ms
7,280 KB
testcase_18 AC 6 ms
7,284 KB
testcase_19 AC 6 ms
7,448 KB
testcase_20 AC 7 ms
7,240 KB
testcase_21 AC 6 ms
7,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int INF=12345678;
int dp[1001][1001];

int main()
{
    int S,T;
    string s,t;
    cin >>S >>T;
    cin >>s >>t;

    fill(dp[0],dp[1001],INF);
    //初期化
    dp[0][0]=0;
    for(int i=1; i<=S; ++i) dp[i][0]=i;
    for(int i=1; i<=T; ++i) dp[0][i]=i;

    //sのi文字目,tのj文字目まで処理が終わっている時の最小の編集距離を計算
    for(int i=1; i<=S; ++i)for(int j=1; j<=T; ++j)
    {
        //変更
        if(s[i-1]==t[j-1]) dp[i][j]=min(dp[i][j],dp[i-1][j-1]);
        else dp[i][j]=min(dp[i][j],dp[i-1][j-1]+1);

        //削除
        dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
        //挿入
        dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
    }

    cout << dp[S][T] << endl;
    return 0;
}
0