結果

問題 No.225 文字列変更(medium)
ユーザー ko-ki-yrrko-ki-yrr
提出日時 2021-02-21 10:47:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,260 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 172,356 KB
実行使用メモリ 11,728 KB
最終ジャッジ日時 2023-10-19 12:05:28
合計ジャッジ時間 3,151 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
11,728 KB
testcase_01 AC 13 ms
11,728 KB
testcase_02 AC 8 ms
11,728 KB
testcase_03 AC 8 ms
11,728 KB
testcase_04 AC 8 ms
11,728 KB
testcase_05 AC 8 ms
11,728 KB
testcase_06 AC 8 ms
11,728 KB
testcase_07 AC 8 ms
11,728 KB
testcase_08 AC 8 ms
11,728 KB
testcase_09 AC 8 ms
11,728 KB
testcase_10 AC 8 ms
11,728 KB
testcase_11 AC 8 ms
11,728 KB
testcase_12 AC 16 ms
11,728 KB
testcase_13 AC 15 ms
11,728 KB
testcase_14 AC 16 ms
11,728 KB
testcase_15 AC 17 ms
11,728 KB
testcase_16 AC 15 ms
11,728 KB
testcase_17 AC 17 ms
11,728 KB
testcase_18 AC 17 ms
11,728 KB
testcase_19 AC 16 ms
11,728 KB
testcase_20 AC 15 ms
11,728 KB
testcase_21 AC 16 ms
11,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll n, m;
string s, t;
const ll INF = 10000000000;
vvll dp(1010, vll(1010, INF));

int main(){
    cin >> n >> m >> s >> t;

    dp[0][0] = 0;

    rep(i, -1, n){
        rep(j, -1, m){
            if(i == -1 && j == -1) continue;

            if(i == -1){
                chmin(dp[i+1][j+1], dp[i+1][j] + 1);
                continue;
            }

            if(j == -1){
                chmin(dp[i+1][j+1], dp[i][j+1] + 1);
                continue;
            }

            if(s[i] == t[j]) chmin(dp[i+1][j+1], dp[i][j]);

            //変更
            chmin(dp[i+1][j+1], dp[i][j] + 1);

            //削除
            chmin(dp[i+1][j+1], dp[i][j+1] + 1);

            //挿入
            chmin(dp[i+1][j+1], dp[i+1][j] + 1);
        }
    }

    cout << dp[n][m] << endl;
}
0