結果

問題 No.225 文字列変更(medium)
ユーザー 三﨑颯
提出日時 2020-09-20 10:50:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 625 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 75,088 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-06-24 10:39:32
合計ジャッジ時間 1,441 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1001));
	dp[0][0] = 0;
	for (int i = -1; i < n; i++) {
		for (int j = -1; j < m; j++) {
			if (i >= 0 && j >= 0) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = dp[i][j];
				}
				else {
					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;
}
0