結果
問題 | No.225 文字列変更(medium) |
ユーザー |
![]() |
提出日時 | 2019-03-13 23:32:57 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 8 ms / 5,000 ms |
コード長 | 1,490 bytes |
コンパイル時間 | 1,230 ms |
コンパイル使用メモリ | 160,848 KB |
実行使用メモリ | 7,168 KB |
最終ジャッジ日時 | 2024-06-24 09:51:08 |
合計ジャッジ時間 | 2,216 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define llong long long int#define ldouble long double#define fore(i, x) for (auto &i : n)#define rep(i, n) for (int i = 0; i < n; ++i)#define repr(i, n) for (int i = n; i >= 0; --i)#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)#define all(x) x.begin(), x.end()#define allr(x) x.rbegin(), x.rend()const static int mod = 1000000000 + 7;const static int inf = INT_MAX / 2;const static llong INF = LLONG_MAX / 2;const static double eps = 1e-6;const static int dx[] = {1, 0, -1, 0};const static int dy[] = {0, 1, 0, -1};template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1;} return 0;}template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1;} return 0;}int levenshtein_distance(string S1, string S2) {int l1 = S1.size(), l2 = S2.size();int dp[l1 + 1][l2 + 1];rep(i, l1 + 1) dp[i][0] = i;rep(i, l2 + 1) dp[0][i] = i;for (int i = 1; i < l1 + 1; ++i) {for (int j = 1; j < l2 + 1; ++j) {int alpha = (S1[i - 1] == S2[j - 1]) ? 0 : 1;dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + alpha));}}return dp[l1][l2];}signed main (int argc, char *argv[]) {cin.tie(0);ios::sync_with_stdio(false);int n, m;cin >> n >> m;string s1, s2;cin >> s1 >> s2;cout << levenshtein_distance(s1, s2) << endl;return 0;}