結果

問題 No.225 文字列変更(medium)
ユーザー airisairis
提出日時 2015-06-12 23:10:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 75,796 KB
実行使用メモリ 7,672 KB
最終ジャッジ日時 2023-09-20 21:08:16
合計ジャッジ時間 1,628 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
7,372 KB
testcase_01 AC 14 ms
7,372 KB
testcase_02 AC 5 ms
7,348 KB
testcase_03 AC 5 ms
7,296 KB
testcase_04 AC 5 ms
7,272 KB
testcase_05 AC 4 ms
7,308 KB
testcase_06 AC 4 ms
7,340 KB
testcase_07 AC 4 ms
7,348 KB
testcase_08 WA -
testcase_09 AC 4 ms
7,424 KB
testcase_10 AC 4 ms
7,344 KB
testcase_11 WA -
testcase_12 AC 17 ms
7,376 KB
testcase_13 AC 18 ms
7,400 KB
testcase_14 AC 17 ms
7,416 KB
testcase_15 AC 11 ms
7,376 KB
testcase_16 AC 17 ms
7,364 KB
testcase_17 AC 12 ms
7,640 KB
testcase_18 AC 15 ms
7,400 KB
testcase_19 AC 17 ms
7,420 KB
testcase_20 WA -
testcase_21 AC 17 ms
7,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#include <complex>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
#define EPS (1e-14)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;

int n, m;
string s, t;

int memo[1005][1005];

int dfs(int i, int j) {
	int res = 0;
	if (i >= n) return m - j;
	if (j >= m) return 2 * (n - i);
	if (memo[i][j] != -1) return memo[i][j];
	if (s[i] == t[j]) {
		res = dfs(i + 1, j + 1);
	}
	else {
		int res1 = dfs(i + 1, j + 1) + 1; //変換
		int res2 = dfs(i + 1, j) + 1;//削除
		int res3 = dfs(i, j + 1) + 1;//挿入
		res = min(res1, min(res2, res3));
	}
	//printf("dfs(%d,%d)=%d\n", i, j, res);
	return memo[i][j] = res;
}

void solve() {
	memset(memo, -1, sizeof(memo));
	cout << dfs(0, 0) << endl;
}

int main() {
	cin >> n >> m;
	cin >> s;
	cin >> t;
	solve();
	return 0;
}


0