結果

問題 No.225 文字列変更(medium)
ユーザー icchiposticchipost
提出日時 2020-07-11 16:22:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,082 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 167,940 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-21 06:10:06
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

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

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

int main() {
  int n, m;
  string S, T;
  cin >> n >> m >> S >> T;
  vector<vector<int>> dp(1001, vector<int>(1001, INF));
  dp[0][0] = 0;
  for (int i = -1; i < n; i++) {
    for (int j = -1; j < m; j++) {
      if (i == -1 && j == -1) continue;
      if (i >= 0 && j >= 0) {
        if (S[i] == T[j]) {
          dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
        }
        else {
          dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + 1);
        } 
      }
      if (i >= 0) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j + 1] + 1);
      if (j >= 0) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i + 1][j] + 1);
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
0