結果

問題 No.225 文字列変更(medium)
ユーザー 37kt_37kt_
提出日時 2016-02-24 15:58:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 2,914 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 145,680 KB
実行使用メモリ 7,556 KB
最終ジャッジ日時 2023-08-25 23:06:32
合計ジャッジ時間 1,940 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,380 KB
testcase_01 AC 7 ms
7,348 KB
testcase_02 AC 4 ms
7,328 KB
testcase_03 AC 4 ms
7,456 KB
testcase_04 AC 4 ms
7,376 KB
testcase_05 AC 4 ms
7,376 KB
testcase_06 AC 3 ms
7,328 KB
testcase_07 AC 4 ms
7,388 KB
testcase_08 AC 5 ms
7,432 KB
testcase_09 AC 4 ms
7,432 KB
testcase_10 AC 4 ms
7,392 KB
testcase_11 AC 4 ms
7,328 KB
testcase_12 AC 10 ms
7,360 KB
testcase_13 AC 8 ms
7,308 KB
testcase_14 AC 10 ms
7,304 KB
testcase_15 AC 10 ms
7,460 KB
testcase_16 AC 8 ms
7,376 KB
testcase_17 AC 10 ms
7,384 KB
testcase_18 AC 10 ms
7,380 KB
testcase_19 AC 8 ms
7,328 KB
testcase_20 AC 10 ms
7,360 KB
testcase_21 AC 8 ms
7,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* 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;
}
0