結果
| 問題 | 
                            No.225 文字列変更(medium)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             airis
                         | 
                    
| 提出日時 | 2015-06-12 23:24:47 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 20 ms / 5,000 ms | 
| コード長 | 1,221 bytes | 
| コンパイル時間 | 605 ms | 
| コンパイル使用メモリ | 81,288 KB | 
| 実行使用メモリ | 11,392 KB | 
| 最終ジャッジ日時 | 2024-12-24 10:11:33 | 
| 合計ジャッジ時間 | 1,577 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 | 
ソースコード
#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;
ll memo[1005][1005];
ll dfs(int i, int j) {
	ll res = 0;
	if (i >= n) return m - j;
	if (j >= m) return n - i;
	if (memo[i][j] != -1) return memo[i][j];
	if (s[i] == t[j]) {
		res = dfs(i + 1, j + 1);
	}
	else {
		ll res1 = dfs(i + 1, j + 1) + 1LL; //変換
		ll res2 = dfs(i + 1, j) + 1LL;//削除
		ll res3 = dfs(i, j + 1) + 1LL;//挿入
		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;
}
            
            
            
        
            
airis