結果

問題 No.225 文字列変更(medium)
ユーザー springrollspringroll
提出日時 2019-02-02 15:25:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 166,048 KB
実行使用メモリ 8,284 KB
最終ジャッジ日時 2023-08-18 12:48:02
合計ジャッジ時間 2,693 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,120 KB
testcase_01 AC 7 ms
8,036 KB
testcase_02 AC 4 ms
8,100 KB
testcase_03 AC 4 ms
8,072 KB
testcase_04 AC 4 ms
8,112 KB
testcase_05 AC 4 ms
8,044 KB
testcase_06 AC 5 ms
8,104 KB
testcase_07 AC 4 ms
8,088 KB
testcase_08 AC 4 ms
8,148 KB
testcase_09 AC 4 ms
8,048 KB
testcase_10 AC 4 ms
8,028 KB
testcase_11 AC 4 ms
8,052 KB
testcase_12 AC 8 ms
8,040 KB
testcase_13 AC 8 ms
8,088 KB
testcase_14 AC 8 ms
8,092 KB
testcase_15 AC 8 ms
8,080 KB
testcase_16 AC 8 ms
8,100 KB
testcase_17 AC 8 ms
8,284 KB
testcase_18 AC 8 ms
8,120 KB
testcase_19 AC 8 ms
8,112 KB
testcase_20 AC 7 ms
8,060 KB
testcase_21 AC 8 ms
8,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

const int INF = 1<<29;

int n, m;
string s, t;
int dp[1100][1100];

int main() {
	cin >> n >> m;
	cin >> s >> t;
	
	for(int i=0; i<1100; i++) for(int j=0; j<1100; j++) dp[i][j] = INF;
	dp[0][0] = 0;

	for (int i = -1; i < (int)s.size(); i++) {
		for (int j = -1; j < (int)t.size(); j++) {
			if(i==-1 && j==-1) continue;
			if (i >= 0 && j >= 0) {
				if(s[i] == t[j]) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);
				else dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][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[s.size()][t.size()] << endl;
}
0