結果

問題 No.225 文字列変更(medium)
ユーザー Haita YukiHaita Yuki
提出日時 2021-04-06 20:57:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,284 bytes
コンパイル時間 1,360 ms
コンパイル使用メモリ 99,712 KB
実行使用メモリ 7,124 KB
最終ジャッジ日時 2023-09-02 12:21:55
合計ジャッジ時間 2,029 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,816 KB
testcase_01 AC 6 ms
6,140 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 8 ms
6,792 KB
testcase_13 AC 8 ms
7,100 KB
testcase_14 AC 8 ms
7,036 KB
testcase_15 AC 7 ms
6,900 KB
testcase_16 AC 7 ms
6,908 KB
testcase_17 AC 7 ms
7,124 KB
testcase_18 AC 7 ms
6,724 KB
testcase_19 AC 8 ms
6,844 KB
testcase_20 AC 7 ms
6,728 KB
testcase_21 AC 7 ms
6,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <ctime>
#include <functional>
#include <set>
#include <tuple>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define P pair<int, int>
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Graph vector<vector<int>>
#define fi first
#define se second
#define pb push_back
typedef vector<int> vint;
typedef vector<bool> vbool;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

int main()
{
  int n, m;
  cin >> n >> m;
  string S, T;
  cin >> S >> T;

  int dp[n + 1][m + 1];
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++)
  {
    dp[i][0] = i;
  }
  for (int j = 1; j <= m; j++)
  {
    dp[0][j] = j;
  }

  rep(i, n)
  {
    rep(j, m)
    {
      if (S[i] == T[j])
      {
        dp[i + 1][j + 1] = dp[i][j];
      }
      else
      {
        dp[i + 1][j + 1] = min(dp[i][j], min(dp[i + 1][j], dp[i][j + 1])) + 1;
      }
    }
  }

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