結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 8 ms
7,680 KB
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 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 11 ms
7,296 KB
testcase_13 WA -
testcase_14 AC 11 ms
7,552 KB
testcase_15 AC 11 ms
7,424 KB
testcase_16 AC 11 ms
7,552 KB
testcase_17 AC 11 ms
7,296 KB
testcase_18 AC 11 ms
7,168 KB
testcase_19 AC 10 ms
7,424 KB
testcase_20 WA -
testcase_21 AC 10 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[1001], t[1001];
	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;
	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]);
			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]);
}
0