結果

問題 No.225 文字列変更(medium)
ユーザー beetbeet
提出日時 2018-11-07 11:46:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 686 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 201,532 KB
実行使用メモリ 11,576 KB
最終ジャッジ日時 2024-04-30 22:22:25
合計ジャッジ時間 3,349 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,416 KB
testcase_01 AC 8 ms
11,448 KB
testcase_02 AC 5 ms
11,400 KB
testcase_03 AC 5 ms
11,420 KB
testcase_04 AC 5 ms
11,472 KB
testcase_05 AC 6 ms
11,372 KB
testcase_06 AC 6 ms
11,576 KB
testcase_07 AC 5 ms
11,400 KB
testcase_08 AC 5 ms
11,520 KB
testcase_09 AC 5 ms
11,380 KB
testcase_10 AC 5 ms
11,392 KB
testcase_11 AC 6 ms
11,412 KB
testcase_12 AC 11 ms
11,412 KB
testcase_13 AC 10 ms
11,456 KB
testcase_14 AC 10 ms
11,516 KB
testcase_15 AC 11 ms
11,508 KB
testcase_16 AC 10 ms
11,336 KB
testcase_17 AC 11 ms
11,392 KB
testcase_18 AC 11 ms
11,388 KB
testcase_19 AC 10 ms
11,380 KB
testcase_20 AC 10 ms
11,376 KB
testcase_21 AC 10 ms
11,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 1010;
Int dp[MAX][MAX];
signed main(){
  Int n,m;
  cin>>n>>m;
  string s,t;
  cin>>s>>t;

  s+='$';
  t+='$';
  
  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      dp[i][j]=1e9;

  dp[0][0]=0;
  for(Int i=0;i<=n;i++){
    for(Int j=0;j<=m;j++){
      chmin(dp[i+1][j+1],dp[i][j]+(s[i]!=t[j]));
      chmin(dp[i+1][j],dp[i][j]+1);
      chmin(dp[i][j+1],dp[i][j]+1);
    }
  }
  
  cout<<dp[n][m]<<endl;
  return 0;
}
0