結果
問題 |
No.225 文字列変更(medium)
|
ユーザー |
![]() |
提出日時 | 2018-11-07 11:46:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 51 ms / 5,000 ms |
コード長 | 686 bytes |
コンパイル時間 | 1,896 ms |
コンパイル使用メモリ | 193,524 KB |
最終ジャッジ日時 | 2025-01-06 15:42:55 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#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; }