結果

問題 No.225 文字列変更(medium)
ユーザー dnishdnish
提出日時 2017-04-28 16:56:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 416 bytes
コンパイル時間 2,913 ms
コンパイル使用メモリ 165,792 KB
実行使用メモリ 7,276 KB
最終ジャッジ日時 2023-10-11 18:57:11
合計ジャッジ時間 2,528 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,004 KB
testcase_01 AC 6 ms
7,276 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,356 KB
testcase_12 AC 6 ms
6,976 KB
testcase_13 AC 6 ms
7,216 KB
testcase_14 AC 6 ms
7,140 KB
testcase_15 AC 6 ms
6,972 KB
testcase_16 AC 6 ms
7,216 KB
testcase_17 AC 5 ms
6,996 KB
testcase_18 AC 6 ms
6,880 KB
testcase_19 AC 6 ms
7,068 KB
testcase_20 AC 6 ms
6,844 KB
testcase_21 AC 6 ms
6,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define p(S) cout<<(S)<<endl
using namespace std;

int dp[1001][1001];
int main(){
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	REP(i,0,n+1) dp[i][0]=i;
	REP(i,0,m+1) dp[0][i]=i;
	REP(i,0,n){
		REP(j,0,m){
			dp[i+1][j+1]=min(dp[i+1][j],dp[i][j+1])+1;
			dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(s[i]!=t[j]));
		}
	}
	p(dp[n][m]);
	return 0;
}
0