結果

問題 No.225 文字列変更(medium)
ユーザー kosakkunkosakkun
提出日時 2017-06-21 07:21:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,077 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 97,348 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-04-10 07:00:05
合計ジャッジ時間 1,695 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 6 ms
7,040 KB
testcase_14 AC 5 ms
7,040 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 5 ms
6,940 KB
testcase_19 AC 5 ms
6,940 KB
testcase_20 AC 5 ms
6,940 KB
testcase_21 AC 5 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
typedef long long ll;

template <class S> int LevenshteinDistance(const S &A, const S &B) {
   vector< vector<int> > dist(A.size()+1,vector<int>(B.size()+1));
   for (int i = 0; i <= A.size(); i++) dist[i][0] = i;
   for (int i = 0; i <= B.size(); i++) dist[0][i] = i;
   for (int i = 0; i < A.size(); i++) {
      for (int j = 0; j < B.size(); j++) {
         dist[i+1][j+1] = min(dist[i][j+1], dist[i+1][j]) + 1;
         dist[i+1][j+1] = min(dist[i+1][j+1], dist[i][j] + (A[i]!=B[j]));
      }
   }
   return dist[A.size()][B.size()];
}

int main() {

  int N,M;
  string A,B;

  cin >> N >> M;
  cin >> A >> B;

  cout << LevenshteinDistance(A,B) << endl;

  return 0;
}
0