結果

問題 No.225 文字列変更(medium)
ユーザー Tatsuro MiyazakiTatsuro Miyazaki
提出日時 2018-07-26 03:23:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,253 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 73,524 KB
実行使用メモリ 10,856 KB
最終ジャッジ日時 2023-09-10 05:39:25
合計ジャッジ時間 1,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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, -1, n) {
		rep(j, -1, m) {
			if(i == -1 && j == -1) continue;
			if(s[i] != t[j]) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + 1);
			else dp[i + 1][j + 1] = min(dp[i][j], dp[i + 1][j + 1]);
			if(i >= 0) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j + 1] + 1);
			if(j >= 0) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i + 1][j] + 1);
		}
	}

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