結果

問題 No.225 文字列変更(medium)
ユーザー FF256grhyFF256grhy
提出日時 2015-06-13 01:33:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 822 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 26,188 KB
実行使用メモリ 6,924 KB
最終ジャッジ日時 2023-08-25 22:47:10
合計ジャッジ時間 1,224 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int min(int, int, int);

int n, m;
char a[1001], b[1001];
int memo[1001][1001];

int main(void) {
	scanf("%d %d%s%s", &n, &m, a, b);
	
	int i, j;
	i = 0; while(a[i] != '\0') { i++; } int la = i;
	i = 0; while(b[i] != '\0') { i++; } int lb = i;

	for(i = 1; i <= la; i++) { memo[i][0] = i; } // 番兵をセット
	for(j = 1; j <= lb; j++) { memo[0][j] = j; }
	
	for(i = 1; i <= la; i++) { // 1ずれてるので、memo[i][j] は (a[i-1], b[j-1]) 相当
	for(j = 1; j <= lb; j++) {
		int v0 = memo[i - 1][j - 1] - (a[i - 1] == b[j - 1]); // change
		int v1 = memo[i - 1][j    ]; // delete
		int v2 = memo[i    ][j - 1]; // insert
		memo[i][j] = min(v0, v1, v2) + 1;
	}
	}
	
	printf("%d\n", memo[la][lb]);
	return 0;
}

int min(int x, int y, int z) {
	int w = (x < y) ? x : y;
	return (w < z) ? w : z;
}
0