結果

問題 No.225 文字列変更(medium)
ユーザー hotpepsihotpepsi
提出日時 2016-01-11 22:49:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 680 bytes
コンパイル時間 1,180 ms
コンパイル使用メモリ 63,372 KB
実行使用メモリ 7,584 KB
最終ジャッジ日時 2023-10-19 22:49:38
合計ジャッジ時間 1,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>

using namespace std;

int main(int argc, char *argv[]) {
	int N, M;
	string S, T;
	cin >> N >> M >> S >> T;
	int dp[1001][1001] = {}, slen = S.length(), tlen = T.length();
	for (int j = 1; j <= tlen; ++j) {
		dp[0][j] = j;
	}
	for (int i = 1; i <= slen; ++i) {
		for (int j = 1; j <= tlen; ++j) {
			int cost = min(dp[i - 1][j] + 1, dp[i - 1][j - 1] + 1);
			if (j > 1) {
				cost = min(cost, dp[i][j - 1] + 1);
			}
			if (S[i - 1] == T[j - 1]) {
				cost = min(cost, dp[i - 1][j - 1]);
			}
			dp[i][j] = cost;
		}
	}
	int ans = dp[slen][tlen];
	cout << ans << endl;
	return 0;
}
0