結果

問題 No.225 文字列変更(medium)
ユーザー Kmcode1Kmcode1
提出日時 2015-06-12 22:30:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,116 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 90,564 KB
実行使用メモリ 8,340 KB
最終ジャッジ日時 2023-08-25 22:26:46
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,904 KB
testcase_01 AC 13 ms
8,340 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 18 ms
8,016 KB
testcase_13 AC 17 ms
8,180 KB
testcase_14 AC 17 ms
8,236 KB
testcase_15 AC 19 ms
7,944 KB
testcase_16 AC 17 ms
8,208 KB
testcase_17 AC 19 ms
7,984 KB
testcase_18 AC 18 ms
8,036 KB
testcase_19 AC 16 ms
8,340 KB
testcase_20 AC 16 ms
8,060 KB
testcase_21 AC 17 ms
8,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;

int n;
int m;

int dp[1002][1002];
string s;
string t;
bool use[1002][1002];
inline int dfs(int a, int b){
	if (a == s.size() && b == t.size()){
		return 0;
	}
	if (a == s.size()){
		return t.size() - b;
	}
	if (b == t.size()){
		return s.size() - a;
	}
	if (use[a][b]){
		return dp[a][b];
	}
	use[a][b] = true;
	dp[a][b] = INT_MAX;
	if (s[a] == t[b]){
		dp[a][b] = dfs(a + 1, b + 1);
	}
	
	dp[a][b] = min(dp[a][b],dfs(a + 1, b + 1) + 1);
	dp[a][b] = min(dp[a][b], dfs(a + 1, b) + 1);
	dp[a][b] = min(dp[a][b], dfs(a, b + 1) + 1);
	return dp[a][b];
}
int main(){
	cin >> n;
	cin >> m;
	cin >> s;
	cin >> t;
	int ans = dfs(0, 0);
	cout << ans << endl;
	return 0;
}
0