結果
| 問題 | 
                            No.225 文字列変更(medium)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-06-12 22:47:52 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 581 bytes | 
| コンパイル時間 | 583 ms | 
| コンパイル使用メモリ | 59,992 KB | 
| 実行使用メモリ | 10,780 KB | 
| 最終ジャッジ日時 | 2024-07-06 15:55:49 | 
| 合計ジャッジ時間 | 12,896 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | TLE * 1 -- * 21 | 
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
int solve(string s, string t, int n, int m, int itr = 0){
  if(itr == n)
    return 0;
  if(itr == m)
    return n - m;
  if(s[itr] == t[itr])
    return solve(s, t, n, m, itr + 1);
  int mincost;
  mincost = solve(s, t, n, m, itr + 1) + 1;
  mincost = min(mincost, solve(s, t.substr(1, m - 1), n, m - 1, itr) + 1);
  mincost = min(mincost, solve(s, "a" + t, n, m + 1, itr + 1) + 1);
  return mincost;
}
int main(){
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  cout << solve(t, s, m, n) << endl;
}