結果

問題 No.225 文字列変更(medium)
ユーザー icchiposticchipost
提出日時 2020-07-11 16:11:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,038 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 168,672 KB
実行使用メモリ 7,600 KB
最終ジャッジ日時 2023-08-03 06:52:28
合計ジャッジ時間 2,745 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,432 KB
testcase_01 AC 6 ms
7,288 KB
testcase_02 AC 4 ms
7,280 KB
testcase_03 AC 4 ms
7,296 KB
testcase_04 AC 5 ms
7,328 KB
testcase_05 WA -
testcase_06 AC 5 ms
7,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 5 ms
7,280 KB
testcase_10 AC 4 ms
7,268 KB
testcase_11 AC 4 ms
7,280 KB
testcase_12 AC 7 ms
7,288 KB
testcase_13 WA -
testcase_14 AC 7 ms
7,336 KB
testcase_15 AC 7 ms
7,332 KB
testcase_16 AC 7 ms
7,372 KB
testcase_17 AC 7 ms
7,316 KB
testcase_18 AC 7 ms
7,284 KB
testcase_19 AC 7 ms
7,432 KB
testcase_20 WA -
testcase_21 AC 7 ms
7,344 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 = 0; i < S.size(); i++) {
    for (int j = 0; j < T.size(); j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = min({
          dp[i + 1][j + 1],
          dp[i][j],
          dp[i][j + 1] + 1,
          dp[i + 1][j] + 1
        });
      }
      else {
        dp[i + 1][j + 1] = min({
          dp[i + 1][j + 1],
          dp[i][j] + 1,
          dp[i][j + 1] + 1,
          dp[i + 1][j] + 1
        }); 
      }
    }
  }
  cout << dp[S.size()][T.size()] << endl;
  return 0;
}
0