結果

問題 No.225 文字列変更(medium)
ユーザー 沙耶花
提出日時 2021-11-16 19:41:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 4,132 ms
コンパイル使用メモリ 252,440 KB
最終ジャッジ日時 2025-01-25 18:47:38
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	
	vector dp(n+1,vector<int>(m+1,Inf));
	dp[0][0] = 0;
	
	rep(i,n+1){
		rep(j,m+1){
			if(i!=n)dp[i+1][j] = min(dp[i+1][j],dp[i][j]+1);
			if(j!=m)dp[i][j+1] = min(dp[i][j+1],dp[i][j]+1);
			if(i!=n&&j!=m){
				int cost = 0;
				if(s[i]!=t[j])cost = 1;
				dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+cost);
			}
		}
	}
	cout<<dp[n][m]<<endl;
	
	return 0;
}
0