結果
問題 | No.225 文字列変更(medium) |
ユーザー |
![]() |
提出日時 | 2015-06-12 23:14:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,227 bytes |
コンパイル時間 | 840 ms |
コンパイル使用メモリ | 81,496 KB |
実行使用メモリ | 11,476 KB |
最終ジャッジ日時 | 2024-07-06 15:56:21 |
合計ジャッジ時間 | 1,918 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; ll memo[1005][1005]; ll dfs(int i, int j) { ll 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 { 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; }