結果

問題 No.225 文字列変更(medium)
ユーザー utgwkkutgwkk
提出日時 2015-10-30 15:11:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 701 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 145,812 KB
実行使用メモリ 7,392 KB
最終ジャッジ日時 2023-08-25 23:06:26
合計ジャッジ時間 2,142 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,868 KB
testcase_01 AC 4 ms
7,280 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 4 ms
6,956 KB
testcase_13 AC 5 ms
7,392 KB
testcase_14 AC 4 ms
7,204 KB
testcase_15 AC 4 ms
7,096 KB
testcase_16 AC 4 ms
7,152 KB
testcase_17 AC 5 ms
7,092 KB
testcase_18 AC 5 ms
7,004 KB
testcase_19 AC 4 ms
7,112 KB
testcase_20 AC 4 ms
6,956 KB
testcase_21 AC 4 ms
7,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
const int MAX_S = 1000;

int ld(string s1, string s2){
  int dp[MAX_S+1][MAX_S+1];
  int l1 = s1.size(), l2 = s2.size();
  REP(i,l1+1) dp[i][0] = i;
  REP(i,l2+1) dp[0][i] = i;
  FOR(i,1,l1+1) FOR(j,1,l2+1){
    int cost = (s1[i-1] == s2[j-1]) ? 0 : 1;
    dp[i][j] = min({
                    dp[i-1][j]+1,     // Insertion
                    dp[i][j-1]+1,     // Deletion
                    dp[i-1][j-1]+cost // Replace
                   });
  }
  return dp[l1][l2];
}

int main(){
  int n,m; cin >> n >> m;
  string s1, s2;
  cin >> s1 >> s2;
  cout << ld(s1, s2) << endl;
}
0