結果

問題 No.225 文字列変更(medium)
ユーザー albicillaalbicilla
提出日時 2015-06-15 17:04:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 70,996 KB
実行使用メモリ 7,392 KB
最終ジャッジ日時 2023-08-25 22:57:09
合計ジャッジ時間 1,607 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,824 KB
testcase_01 AC 6 ms
7,392 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 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 8 ms
7,128 KB
testcase_13 AC 7 ms
7,196 KB
testcase_14 AC 7 ms
7,160 KB
testcase_15 AC 10 ms
6,916 KB
testcase_16 AC 7 ms
7,120 KB
testcase_17 AC 10 ms
6,876 KB
testcase_18 AC 9 ms
6,968 KB
testcase_19 AC 7 ms
7,036 KB
testcase_20 AC 8 ms
6,928 KB
testcase_21 AC 8 ms
7,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<sstream>
#include<typeinfo>
#include<fstream>
 
using namespace std;
 
int n, m;
 
char s[1001],t[1001];
 
int dp[1001][1001];
 
 
 
void solve(){
	for (int i = 0; i <= n; ++i){
		for (int j = 0; j <= m; ++j){
			if (i == 0){
				dp[i][j] = j;
				continue;
			}
			if (j == 0){
				dp[i][j] = i;
				continue;
			}
			if (s[i - 1] != t[j - 1]){
				dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1));
			}
			else if (s[i - 1] == t[j - 1]){
				dp[i][j] = dp[i - 1][j - 1];
			}
 
		}
	}
 
}
 
int main(){
 
	cin >> n >> m >> s >> t;
 
 
	solve();
 
 
	cout << dp[n][m] << endl;
 
	return 0;
}
0