結果

問題 No.225 文字列変更(medium)
ユーザー Tatsuro MiyazakiTatsuro Miyazaki
提出日時 2018-07-26 03:30:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,178 bytes
コンパイル時間 1,039 ms
コンパイル使用メモリ 73,824 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-09-10 06:14:36
合計ジャッジ時間 2,273 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,364 KB
testcase_01 AC 6 ms
8,592 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 7 ms
10,288 KB
testcase_13 AC 8 ms
10,920 KB
testcase_14 AC 7 ms
10,932 KB
testcase_15 AC 8 ms
10,356 KB
testcase_16 AC 8 ms
10,400 KB
testcase_17 AC 7 ms
10,328 KB
testcase_18 AC 7 ms
10,104 KB
testcase_19 AC 7 ms
10,520 KB
testcase_20 AC 7 ms
9,980 KB
testcase_21 AC 7 ms
10,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	ll dp[n + 1][m + 1];
	rep(i, 0, n + 1) rep(j, 0 , m + 1) dp[i][j] = INF;
	dp[0][0] = 0;
	rep(i, 0, n + 1) dp[i][0] = i;
	rep(j, 0, m + 1) dp[0][j] = j;
	rep(i, 0, n) {
		rep(j, 0, m) {
			if(s[i] == t[j]) dp[i + 1][j + 1] = min(dp[i][j], min(dp[i + 1][j] + 1, dp[i][j + 1] + 1));
			else dp[i + 1][j + 1] = min(dp[i][j] + 1, min(dp[i + 1][j] + 1, dp[i][j + 1] + 1));

		}
	}

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