結果

問題 No.225 文字列変更(medium)
ユーザー sugim48sugim48
提出日時 2015-06-12 22:25:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,136 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 80,056 KB
実行使用メモリ 7,188 KB
最終ジャッジ日時 2023-08-25 22:24:40
合計ジャッジ時間 1,438 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,140 KB
testcase_01 AC 4 ms
5,900 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 7 ms
6,924 KB
testcase_13 AC 6 ms
7,128 KB
testcase_14 AC 6 ms
7,088 KB
testcase_15 AC 5 ms
6,916 KB
testcase_16 AC 6 ms
6,912 KB
testcase_17 AC 5 ms
6,896 KB
testcase_18 AC 6 ms
6,776 KB
testcase_19 AC 5 ms
7,100 KB
testcase_20 AC 5 ms
6,740 KB
testcase_21 AC 6 ms
7,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int n, m; cin >> n >> m;
	string S, T; cin >> S >> T;
	vector<vector<int> > dp(n + 1, vector<int>(m + 1));
	for (int i = 0; i <= n; i++)
		dp[i][0] = i;
	for (int j = 0; j <= m; j++)
		dp[0][j] = j;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1;
			if (S[i - 1] == T[j - 1])
				dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
			else
				dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);
		}
	cout << dp[n][m] << endl;
}
0