結果

問題 No.225 文字列変更(medium)
ユーザー ko-ki-yrrko-ki-yrr
提出日時 2021-02-21 10:41:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 974 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 171,756 KB
実行使用メモリ 11,732 KB
最終ジャッジ日時 2023-10-19 12:00:32
合計ジャッジ時間 2,929 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,708 KB
testcase_01 AC 11 ms
11,708 KB
testcase_02 AC 7 ms
11,708 KB
testcase_03 AC 7 ms
11,708 KB
testcase_04 AC 8 ms
11,708 KB
testcase_05 WA -
testcase_06 AC 8 ms
11,708 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 7 ms
11,708 KB
testcase_10 AC 8 ms
11,708 KB
testcase_11 AC 7 ms
11,708 KB
testcase_12 AC 14 ms
11,708 KB
testcase_13 WA -
testcase_14 AC 14 ms
11,708 KB
testcase_15 AC 14 ms
11,708 KB
testcase_16 AC 13 ms
11,708 KB
testcase_17 AC 14 ms
11,708 KB
testcase_18 AC 14 ms
11,708 KB
testcase_19 AC 13 ms
11,708 KB
testcase_20 WA -
testcase_21 AC 14 ms
11,708 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, 0, n){
        rep(j, 0, m){
            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