結果
| 問題 | No.225 文字列変更(medium) |
| コンテスト | |
| ユーザー |
airis
|
| 提出日時 | 2015-06-12 23:10:33 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,227 bytes |
| 記録 | |
| コンパイル時間 | 643 ms |
| コンパイル使用メモリ | 81,292 KB |
| 実行使用メモリ | 7,540 KB |
| 最終ジャッジ日時 | 2024-07-06 15:56:08 |
| 合計ジャッジ時間 | 1,358 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 3 |
ソースコード
#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;
}
airis