結果

問題 No.225 文字列変更(medium)
ユーザー oshiborioshibori
提出日時 2017-12-30 13:56:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,135 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 168,448 KB
実行使用メモリ 6,780 KB
最終ジャッジ日時 2023-08-23 11:00:15
合計ジャッジ時間 2,788 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,644 KB
testcase_01 AC 4 ms
5,704 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 6 ms
6,456 KB
testcase_13 AC 6 ms
6,780 KB
testcase_14 AC 6 ms
6,756 KB
testcase_15 AC 6 ms
6,452 KB
testcase_16 AC 6 ms
6,716 KB
testcase_17 AC 6 ms
6,448 KB
testcase_18 AC 6 ms
6,456 KB
testcase_19 AC 6 ms
6,516 KB
testcase_20 AC 6 ms
6,456 KB
testcase_21 AC 5 ms
6,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
  rep(i, 1, n + 1) dp[i][0] = i;
  rep(i, 1, m + 1) dp[0][i] = i;
  rep(i, 1, n + 1) rep(j, 1, m + 1) dp[i][j] =
      min(dp[i - 1][j - 1] + (s[i - 1] != t[j - 1]),
          min(dp[i - 1][j], dp[i][j - 1]) + 1);
  cout << dp[n][m] << endl;

  return 0;
}
0