結果
問題 | No.225 文字列変更(medium) |
ユーザー |
![]() |
提出日時 | 2016-02-24 15:58:36 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 12 ms / 5,000 ms |
コード長 | 2,914 bytes |
コンパイル時間 | 1,467 ms |
コンパイル使用メモリ | 159,224 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-12-24 10:49:13 |
合計ジャッジ時間 | 2,292 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
/* template.cpp {{{ */ #include <bits/stdc++.h> using namespace std; // #define int long long #define GET_MACRO(a, b, c, d, NAME, ...) NAME #define REP1(n) REP2(i_, n) #define REP2(i, n) REP3(i, 0, n) #define REP3(i, a, b) REP4(i, a, b, 1) #define REP4(i, a, b, s) for (long long i = (a); i < (long long)(b); i += (long long)(s)) #define RREP1(n) RREP2(i_, n) #define RREP2(i, n) RREP3(i, 0, n) #define RREP3(i, a, b) RREP4(i, a, b, 1) #define RREP4(i, a, b, s) for (long long i = (b) - 1; i >= (long long)(a); i -= (long long)(s)) #define rep(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__) #define rrep(...) GET_MACRO(__VA_ARGS__, RREP4, RREP3, RREP2, RREP1)(__VA_ARGS__) #define fs first #define sc second #define all(c) std::begin(c), std::end(c) #define dump(...) std::cerr << "("#__VA_ARGS__") = " << std::make_tuple(__VA_ARGS__) << "\n" #define y0 y0_ #define y1 y1_ #define yn yn_ using uint = unsigned; using ll = long long; using ull = unsigned long long; using ld = long double; template<typename T> using V = vector<T>; template<typename T> using V2 = vector<V<T>>; template<typename T> using V3 = vector<V2<T>>; template<typename T> using V4 = vector<V3<T>>; using vi = V<int>; using vu = V<uint>; using vl = V<ll>; using vul = V<ull>; using vd = V<double>; using vld = V<ld>; template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using maxheap = priority_queue<T>; template<typename T> inline constexpr T sq(T x){ return x * x; } template<typename T, typename U> inline T& chmin(T &x, U y){ if (x > y) x = y; return x; } template<typename T, typename U> inline T& chmax(T &x, U y){ if (x < y) x = y; return x; } const string delimiter = " "; void setDelimiter(const string &d){ const_cast<string &>(delimiter) = d; } template<size_t N, typename ...T> typename enable_if<(N >= sizeof...(T))>::type print_tuple(ostream &, const tuple<T...> &, const string &){ } template<size_t N, typename ...T> typename enable_if<(N < sizeof...(T))>::type print_tuple(ostream &os, const tuple<T...> &x, const string &delim = delimiter){ os << (N > 0 ? delim : "") << get<N>(x); print_tuple<N + 1, T...>(os, x, delim); } template<typename ...T> ostream &operator<<(ostream &os, const tuple<T...> &x){ if (&os == &cerr) print_tuple<0, T...>(os, x, " "); else print_tuple<0, T...>(os, x); return os; } template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &x){ return os << x.first << delimiter << x.second; } /* }}} */ int n, m; string s, t; int dp[1010][1010]; signed main() { cin >> n >> m >> s >> t; fill_n(*dp, 1010 * 1010, 1 << 28); dp[0][0] = 0; rep(i, n + 1) rep(j, m + 1){ if (s[i] == t[j]) chmin(dp[i + 1][j + 1], dp[i][j]); chmin(dp[i + 1][j + 1], dp[i][j] + 1); chmin(dp[i + 1][j], dp[i][j] + 1); chmin(dp[i][j + 1], dp[i][j] + 1); } cout << dp[n][m] << endl; }