結果
| 問題 |
No.225 文字列変更(medium)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-01 10:41:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 5,000 ms |
| コード長 | 1,174 bytes |
| コンパイル時間 | 837 ms |
| コンパイル使用メモリ | 95,320 KB |
| 実行使用メモリ | 6,912 KB |
| 最終ジャッジ日時 | 2024-12-24 10:42:48 |
| 合計ジャッジ時間 | 1,869 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
int LevenshteinDist(const string& s, const string& t)
{
int n = s.size();
int m = t.size();
vector<vector<int> > minCost(n+2, vector<int>(m+2, INT_MAX));
minCost[0][0] = 0;
for(int i=0; i<=n; ++i){
for(int j=0; j<=m; ++j){
minCost[i+1][j] = min(minCost[i+1][j], minCost[i][j] + 1);
minCost[i][j+1] = min(minCost[i][j+1], minCost[i][j] + 1);
if(i < n && j < m && s[i] == t[j])
minCost[i+1][j+1] = min(minCost[i+1][j+1], minCost[i][j]);
else
minCost[i+1][j+1] = min(minCost[i+1][j+1], minCost[i][j] + 1);
}
}
return minCost[n][m];
}
int main()
{
int n, m;
string s, t;
cin >> n >> m >> s >> t;
cout << LevenshteinDist(s, t) << endl;
return 0;
}