結果
問題 |
No.225 文字列変更(medium)
|
ユーザー |
![]() |
提出日時 | 2019-02-21 06:37:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 5,000 ms |
コード長 | 1,409 bytes |
コンパイル時間 | 1,181 ms |
コンパイル使用メモリ | 109,972 KB |
実行使用メモリ | 10,820 KB |
最終ジャッジ日時 | 2024-11-15 19:27:50 |
合計ジャッジ時間 | 2,226 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
/* ---------- STL Libraries ---------- */ // IO library #include <cstdio> #include <fstream> #include <iomanip> #include <ios> #include <iostream> // algorithm library #include <algorithm> #include <cmath> #include <numeric> #include <random> // container library #include <array> #include <bitset> #include <deque> #include <map> #include <unordered_map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll #define P pair<ll, ll> /* ---------- Constants */ const double PI = 3.141592653589793238462643383279; const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ signed main() { int N, M; string s, t; cin >> N >> M >> s >> t; int dp[N+1][M+1]; fill(dp[0], dp[N+1], INF); dp[0][0] = 0; for (int i = 1; i <= N; i++) dp[i][0] = i; for (int j = 1; j <= M; j++) dp[0][j] = j; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { dp[i][j] = min(dp[i-1][j] + 1, dp[i][j-1] + 1); if (s[i-1] == t[j-1]) { dp[i][j] = min(dp[i][j], dp[i-1][j-1]); } else { dp[i][j] = min(dp[i][j], dp[i-1][j-1] + 1); } } } cout << dp[N][M] << endl; return 0; }