結果

問題 No.225 文字列変更(medium)
ユーザー sp4ghetsp4ghet
提出日時 2020-02-25 05:20:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,505 bytes
コンパイル時間 1,866 ms
コンパイル使用メモリ 169,696 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-21 07:13:03
合計ジャッジ時間 2,963 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 8 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 12 ms
7,040 KB
testcase_13 AC 11 ms
7,552 KB
testcase_14 AC 12 ms
7,296 KB
testcase_15 AC 12 ms
7,168 KB
testcase_16 AC 11 ms
7,168 KB
testcase_17 AC 13 ms
7,168 KB
testcase_18 AC 12 ms
7,040 KB
testcase_19 AC 11 ms
7,040 KB
testcase_20 AC 12 ms
6,944 KB
testcase_21 AC 12 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, INT32_MAX));

    dp[0][0] = 0;
    rep(i, n)
    {
        rep(j, m)
        {
            if (s.at(i) != t.at(j))
            {
                chmin(dp[i + 1][j + 1], dp[i][j] + 1);
            }
            else
            {
                chmin(dp[i + 1][j + 1], dp[i][j]);
            }

            chmin(dp[i + 1][j], dp[i][j] + 1);
            chmin(dp[i][j + 1], dp[i][j] + 1);
            chmin(dp[i + 1][j + 1], dp[i + 1][j] + 1);
            chmin(dp[i + 1][j + 1], dp[i][j + 1] + 1);
        }
    }
    int ans = dp[n][m];

    cout << ans << endl;

    return 0;
}
0