結果

問題 No.273 回文分解
ユーザー bal4ubal4u
提出日時 2019-04-18 20:50:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 1,248 ms
コンパイル使用メモリ 30,636 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 16:24:06
合計ジャッジ時間 1,906 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 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 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.273 回文分解
// 2019.4.18 bal4u

#include <stdio.h>
#include <string.h>

#if 0
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	char *p = s;
	char c;
	do *s++ = '_', c = gc(), *s++ = c;
	while (c > ' ');
	*--s = 0;
	return s - p;
}

int r[105];
char s[105];

void manacher(char *s, int w)
{
	int i = 0, j = 0, k = 1;
	while (i < w) {
		while (i >= j && i + j < w && s[i - j] == s[i + j]) j++;
		r[i] = j;
		k = 1; while (i >= k && i + k < w && k + r[i - k] < j) {
			r[i + k] = r[i - k], k++;
		}
		i += k; j -= k;
	}
}

int main()
{
	int i, j, p, max, w = ins(s);
	for (j = 0; j < 2; j++) {
		max = 0, manacher(s, w);
		for (i = 0; i < w; i++) {
			if (r[i] > max) max = r[i], p = i;
		}
		if (w > 2*max) break;
		w -= 2, s[w] = 0;
		memset(r, 0, sizeof(r));
	}
	printf("%d\n", max-1);
	return 0;
}
0