結果

問題 No.225 文字列変更(medium)
ユーザー bal4ubal4u
提出日時 2019-04-14 15:30:12
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,072 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 29,888 KB
実行使用メモリ 5,688 KB
最終ジャッジ日時 2023-10-19 05:30:46
合計ジャッジ時間 2,095 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,476 KB
testcase_01 AC 4 ms
5,688 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 4 ms
5,328 KB
testcase_13 AC 4 ms
5,588 KB
testcase_14 AC 4 ms
5,564 KB
testcase_15 AC 4 ms
5,388 KB
testcase_16 AC 4 ms
5,596 KB
testcase_17 AC 4 ms
5,348 KB
testcase_18 AC 4 ms
5,300 KB
testcase_19 AC 4 ms
5,480 KB
testcase_20 AC 4 ms
5,320 KB
testcase_21 AC 4 ms
5,468 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: note: in expansion of macro 'gc'
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.225 文字列変更(medium)
// 2019.4.14 bal4u

#include <stdio.h>

//// 高速入力
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()   // 整数の入力(負数に対応)
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	do *s = gc();
	while (*s++ > ' ');
	*(s - 1) = 0;
}

int M[1005][1005];

int LCS(char *str1, int len1, char *str2, int len2)
{
	int  i, j;

	for (j = 0; j <= len1; j++) M[j][0] = j;
	for (i = 0; i <= len2; i++) M[0][i] = i;
	for (j = 1; j <= len1; j++) {
		for (i = 1; i <= len2; i++) {
			int d, min;
			d = (str1[j - 1] != str2[i - 1]);
			min = M[j - 1][i] + 1;
			if (min > M[j][i - 1] + 1) min = M[j][i - 1] + 1;
			if (min > M[j - 1][i - 1] + d) min = M[j - 1][i - 1] + d;
			M[j][i] = min;
		}
	}
	return M[len1][len2];
}

int n, m;
char S[1005], T[1005];

int main()
{
	n = in(), m = in();
	ins(S), ins(T);
	printf("%d\n", LCS(S, n, T, m));
	return 0;
}
0