結果

問題 No.225 文字列変更(medium)
ユーザー Tatsuro MiyazakiTatsuro Miyazaki
提出日時 2018-12-12 13:30:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,517 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 74,180 KB
実行使用メモリ 7,200 KB
最終ジャッジ日時 2023-10-25 08:23:46
合計ジャッジ時間 1,931 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,916 KB
testcase_01 AC 6 ms
5,952 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 8 ms
6,908 KB
testcase_13 WA -
testcase_14 AC 8 ms
7,100 KB
testcase_15 AC 10 ms
6,932 KB
testcase_16 AC 8 ms
6,984 KB
testcase_17 AC 10 ms
6,952 KB
testcase_18 AC 10 ms
6,836 KB
testcase_19 AC 7 ms
6,964 KB
testcase_20 WA -
testcase_21 AC 8 ms
6,948 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--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	// dp[i][j] : i, j番目まででの最小コスト
	// dp[i + 1][j + 1] = dp[i][j] + c[i][j]
	// 					  dp[i + 1][j] + c[i][j]
	// 					  dp[i][j + 1] + c[i][j]
	int n, m;
	cin >> n >> m;
	string S, T;
	cin >> S >> T;
	int s_length = S.size();
	int t_length = T.size();

	int dp[s_length + 1][t_length + 1];
	fill((int*)dp, (int*)(dp + s_length + 1), 1e9);
	dp[0][0] = 0;

	rep(i, 0, s_length) rep(j, 0, t_length) {
		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[s_length][t_length] << endl;


}
0