結果

問題 No.225 文字列変更(medium)
ユーザー Genki TakahashiGenki Takahashi
提出日時 2021-07-20 18:45:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 985 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 165,568 KB
実行使用メモリ 7,684 KB
最終ジャッジ日時 2023-09-24 12:52:16
合計ジャッジ時間 2,832 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,408 KB
testcase_01 AC 6 ms
7,480 KB
testcase_02 AC 3 ms
7,352 KB
testcase_03 AC 3 ms
7,540 KB
testcase_04 AC 4 ms
7,392 KB
testcase_05 AC 3 ms
7,552 KB
testcase_06 AC 4 ms
7,420 KB
testcase_07 AC 4 ms
7,540 KB
testcase_08 AC 4 ms
7,552 KB
testcase_09 AC 3 ms
7,416 KB
testcase_10 AC 4 ms
7,452 KB
testcase_11 AC 4 ms
7,412 KB
testcase_12 AC 7 ms
7,436 KB
testcase_13 AC 7 ms
7,432 KB
testcase_14 AC 7 ms
7,356 KB
testcase_15 AC 6 ms
7,560 KB
testcase_16 AC 7 ms
7,420 KB
testcase_17 AC 6 ms
7,484 KB
testcase_18 AC 7 ms
7,360 KB
testcase_19 AC 7 ms
7,412 KB
testcase_20 AC 7 ms
7,400 KB
testcase_21 AC 7 ms
7,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
const double PI = 3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = 1LL << 50;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};
const int ddx[] = {0,1,0,-1,1,1,-1,-1}, ddy[] = {1,0,-1,0,1,-1,1,-1};


const int inf = 1<<23;
int main() {
    string  S,T;
    int n,m;
    cin >> n >> m;
    cin >> S >> T;
    int dp[1010][1010];
    memset(dp, inf, sizeof(dp));
    rep(i,S.size()+1)dp[i][0] = i;
    rep(i,T.size()+1)dp[0][i] = i;
    
    dp[0][0] = 0;
    rep(i,S.size()) {
        rep(j, T.size()) {
            int tmp = min(dp[i+1][j] + 1,dp[i][j+1] + 1);
            if (S[i]==T[j]) dp[i+1][j+1] = min(dp[i][j], tmp);
            else dp[i+1][j+1] = min(tmp, dp[i][j]+1);
        }
    }
    cout << dp[S.size()][T.size()] << endl;
    return 0;
}
0