結果

問題 No.225 文字列変更(medium)
ユーザー vain0vain0
提出日時 2015-06-12 23:39:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,517 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 74,860 KB
実行使用メモリ 11,656 KB
最終ジャッジ日時 2023-09-20 21:09:19
合計ジャッジ時間 1,714 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
11,508 KB
testcase_01 AC 22 ms
11,356 KB
testcase_02 AC 6 ms
11,220 KB
testcase_03 AC 6 ms
11,204 KB
testcase_04 AC 6 ms
11,160 KB
testcase_05 AC 6 ms
11,160 KB
testcase_06 AC 5 ms
11,164 KB
testcase_07 AC 6 ms
11,212 KB
testcase_08 AC 6 ms
11,248 KB
testcase_09 AC 6 ms
11,276 KB
testcase_10 WA -
testcase_11 AC 6 ms
11,164 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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 ) return m - it;
	if ( it == m ) return 0;

	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