結果

問題 No.225 文字列変更(medium)
ユーザー vain0vain0
提出日時 2015-06-12 23:41:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,515 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 89,124 KB
実行使用メモリ 11,600 KB
最終ジャッジ日時 2023-08-25 22:46:34
合計ジャッジ時間 1,713 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
11,268 KB
testcase_01 AC 14 ms
11,376 KB
testcase_02 AC 4 ms
11,432 KB
testcase_03 AC 6 ms
11,184 KB
testcase_04 AC 5 ms
11,168 KB
testcase_05 AC 5 ms
11,376 KB
testcase_06 AC 6 ms
11,236 KB
testcase_07 AC 5 ms
11,212 KB
testcase_08 AC 5 ms
11,308 KB
testcase_09 AC 5 ms
11,232 KB
testcase_10 AC 4 ms
11,200 KB
testcase_11 AC 5 ms
11,176 KB
testcase_12 AC 16 ms
11,376 KB
testcase_13 AC 18 ms
11,404 KB
testcase_14 AC 18 ms
11,392 KB
testcase_15 AC 11 ms
11,332 KB
testcase_16 AC 17 ms
11,388 KB
testcase_17 AC 11 ms
11,300 KB
testcase_18 AC 16 ms
11,424 KB
testcase_19 AC 18 ms
11,544 KB
testcase_20 AC 16 ms
11,352 KB
testcase_21 AC 17 ms
11,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <functional>
#include <set>
#include <ctime>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#ifndef ONLINE_JUDGE //POJ
# include <complex>
# include <random>
# include <array>
# define mkt make_tuple
# define empb emplace_back
#endif
#ifdef _LOCAL
# include "for_local.h"
#endif
using namespace std;
typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))
#define mkp make_pair
#define all(_X) (_X).begin(), (_X).end()
inline int scani() { int n; scanf("%d", &n); return n; }

int const INF = 1<<29;
int n,m;
string s, t;
int const N = 1000 + 1;

#if 1
int memo[N][N][2];
int dfs(int is, int it, int k) {
	if ( is == n || it == m ) return (n - is) + (m - it);

	auto& x = memo[is][it][k];
	if ( x != INF + 1 ) { return x; }

	if ( s[is] == t[it] ) {
		return x = dfs(is + 1, it + 1, k);
	} else {
		return x =
			min(dfs(is + 1, it + 1, k) + 1,
			min(dfs(is + 1, it, 1 - k) + 1,
				dfs(is, it + 1, 1 - k) + 1));
	}
}
int calc() {
	rep(i, N) rep(j, N) rep(k, 2) memo[i][j][k] = INF + 1;
	return dfs(0, 0, (m - n) & 1);
}
#endif

signed main() {
	cin >> n >> m >> s >> t;
	if ( n > m ) { swap(n, m); swap(s, t); }
	s.append("*"); t.append("*");

	int const c = calc();
	cout << c << endl;
	return 0;
}
0