結果

問題 No.225 文字列変更(medium)
ユーザー itezpaceitezpace
提出日時 2016-06-16 12:24:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 684 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 60,972 KB
実行使用メモリ 7,400 KB
最終ジャッジ日時 2023-08-25 23:08:08
合計ジャッジ時間 1,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,824 KB
testcase_01 AC 6 ms
7,228 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 7 ms
6,964 KB
testcase_13 AC 7 ms
7,208 KB
testcase_14 AC 8 ms
7,132 KB
testcase_15 AC 7 ms
7,152 KB
testcase_16 AC 7 ms
7,400 KB
testcase_17 AC 7 ms
6,900 KB
testcase_18 AC 6 ms
6,864 KB
testcase_19 AC 7 ms
7,036 KB
testcase_20 AC 7 ms
6,832 KB
testcase_21 AC 7 ms
7,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <climits>

using namespace std;

int main(){
  int n,m;
  cin>>n>>m;

  string s,t;
  cin>>s;
  cin>>t;

  int dp[1001][1001];
  for(int i=0; i<n+1; ++i) for(int j=0; j<m+1; ++j) dp[i][j]=INT_MAX;

  dp[0][0]=0;
  for(int i=0; i<n+1; ++i) {
    for(int j=0; j<m+1; ++j) {
      if(i==0) {
        dp[i][j]=j;
      } else if(j==0) {
        dp[i][j]=i;
      } else if(s[i-1]==t[j-1]) {
        dp[i][j]=dp[i-1][j-1];
      } else {
        int d,a,c;
        d=dp[i][j-1];
        a=dp[i-1][j];
        c=dp[i-1][j-1];
        dp[i][j]=min(d,min(a,c))+1;
      }
    }
  }

  cout<<dp[n][m]<<endl;
  
  return 0;
}
0