結果

問題 No.225 文字列変更(medium)
ユーザー drken1215drken1215
提出日時 2015-06-11 23:53:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 707 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 53,148 KB
実行使用メモリ 8,324 KB
最終ジャッジ日時 2023-08-25 22:20:36
合計ジャッジ時間 1,929 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,096 KB
testcase_01 AC 7 ms
8,088 KB
testcase_02 AC 3 ms
8,060 KB
testcase_03 AC 4 ms
8,056 KB
testcase_04 AC 4 ms
8,088 KB
testcase_05 AC 3 ms
8,120 KB
testcase_06 AC 3 ms
8,060 KB
testcase_07 AC 4 ms
8,324 KB
testcase_08 AC 4 ms
8,056 KB
testcase_09 AC 3 ms
8,056 KB
testcase_10 AC 3 ms
8,284 KB
testcase_11 AC 4 ms
8,120 KB
testcase_12 AC 10 ms
8,096 KB
testcase_13 AC 10 ms
8,060 KB
testcase_14 AC 10 ms
8,164 KB
testcase_15 AC 11 ms
8,200 KB
testcase_16 AC 9 ms
8,164 KB
testcase_17 AC 11 ms
8,060 KB
testcase_18 AC 10 ms
8,136 KB
testcase_19 AC 9 ms
8,096 KB
testcase_20 AC 10 ms
8,192 KB
testcase_21 AC 9 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

#define MAX 1100
#define INF 1<<29

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

int n, m;
string S, T;

int dp[MAX][MAX];

int main() {
  while (cin >> n >> m) {
    cin >> S >> T;
    S += "?"; T += "?";
    for (int i = 0; i < MAX; ++i)
      for (int j = 0; j < MAX; ++j)
	dp[i][j] = INF;
    dp[0][0] = 0;
    for (int i = 0; i <= n; ++i) {
      for (int j = 0; j <= m; ++j) {
	if (S[i] == T[j])
	  chmin(dp[i+1][j+1], dp[i][j]);
	else
	  chmin(dp[i+1][j+1], dp[i][j] + 1);
	chmin(dp[i+1][j], dp[i][j] + 1);
	chmin(dp[i][j+1], dp[i][j] + 1);
      }
    }
    cout << dp[n][m] << endl;
  }
}
0