結果

問題 No.225 文字列変更(medium)
ユーザー tailstails
提出日時 2015-06-12 22:36:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 433 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 144,292 KB
実行使用メモリ 7,276 KB
最終ジャッジ日時 2023-08-25 22:43:54
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,884 KB
testcase_01 AC 6 ms
7,252 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 9 ms
6,872 KB
testcase_13 AC 9 ms
7,276 KB
testcase_14 AC 9 ms
7,196 KB
testcase_15 AC 7 ms
7,172 KB
testcase_16 AC 8 ms
7,180 KB
testcase_17 AC 9 ms
6,936 KB
testcase_18 AC 8 ms
6,932 KB
testcase_19 AC 9 ms
7,060 KB
testcase_20 AC 9 ms
7,036 KB
testcase_21 AC 9 ms
7,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n,m;
char s[1001],t[1001];

int dp[1001][1001];

int main(){
	cin >> n >> m >> s >> t;

	for(int i=0;i<=n;++i){
		for(int j=0;j<=m;++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{
				dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1;
			}
		}
	}

	cout << dp[n][m] << endl;

	return 0;
}
0