結果

問題 No.225 文字列変更(medium)
ユーザー fukunagaS4fukunagaS4
提出日時 2020-04-21 10:56:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 817 bytes
コンパイル時間 2,112 ms
コンパイル使用メモリ 193,960 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-16 18:35:14
合計ジャッジ時間 2,868 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

const int INF = 1 << 29;

// dp := 文字列sのi番目を変換して文字列tのj番目までと等しくするまでの最小操作回数
int dp[1010][1010];

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	char s[1010], t[1010];
	scanf("%s%s", s, t);
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= m; j++)
			dp[i][j] = INF;
	dp[0][0] = 0;
	dp[1][0] = -1;
	dp[0][1] = -1;
	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+1], dp[i+1][j] + 1);
			chmin(dp[i+1][j+1], dp[i][j+1] + 1);
		}
	}
	printf("%d\n", dp[n][m] + 1);
}
0