結果

問題 No.225 文字列変更(medium)
ユーザー どららどらら
提出日時 2015-06-12 22:34:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,493 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 79,392 KB
実行使用メモリ 6,856 KB
最終ジャッジ日時 2023-08-25 22:27:11
合計ジャッジ時間 1,492 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,936 KB
testcase_01 AC 5 ms
5,696 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 9 ms
6,640 KB
testcase_13 AC 8 ms
6,740 KB
testcase_14 AC 8 ms
6,856 KB
testcase_15 AC 7 ms
6,744 KB
testcase_16 AC 8 ms
6,552 KB
testcase_17 AC 7 ms
6,516 KB
testcase_18 AC 7 ms
6,548 KB
testcase_19 AC 8 ms
6,484 KB
testcase_20 AC 7 ms
6,584 KB
testcase_21 AC 7 ms
6,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define MAX 1000000000

int solve(const string& S, const string& T){
  std::vector< std::vector<int> > D(S.length()+1, std::vector<int>(T.length()+1, MAX));
  
  rep(i,S.length()+1) D[i][0] = i;
  rep(i,T.length()+1) D[0][i] = i;
  REP(i,1,S.length()+1){
    REP(j,1,T.length()+1){
      int op_nop = MAX;
      if(S[i-1] == T[j-1]){
        op_nop = D[i-1][j-1];
      }
      int op_ins = MAX;
      if(D[i][j-1] != MAX){
        op_ins = D[i][j-1] + 1;
      }
      int op_del = MAX;
      if(D[i-1][j] != MAX){
        op_del = D[i-1][j] + 1;
      }
      int op_rep = MAX;
      if(D[i-1][j-1] != MAX){
        op_rep = D[i-1][j-1] + 1;
      }

      D[i][j] = min(D[i][j], op_nop);
      D[i][j] = min(D[i][j], op_ins);
      D[i][j] = min(D[i][j], op_del);
      D[i][j] = min(D[i][j], op_rep);
    }
  }
  return D[S.length()][T.length()];
}


int main(){
  int n, m;
  string S, T;
  cin >> n >> m;
  cin >> S;
  cin >> T;

  cout << solve(S, T) << endl;

  return 0;
}
0