可爱萌新刚学oi求条
查看原帖
可爱萌新刚学oi求条
754495
KAqvq楼主2025/7/23 19:27

tle on #4,8,9,15,16

#include <bits/stdc++.h>
#define N 22000005

using std::string;

typedef long long LL;
typedef string S;

LL l, d[N], ans;
char t[N];
S s;

inline void manacher() {
	LL r = 0, pos = 0;
	for (LL i = 1; i < l; ++i) {
		d[i] = r < l ? 1 : std::min(d[(pos << 1) - i], r - i);
		while (t[i - d[i]] == t[i + d[i]]) ++d[i];
		if (i + d[i] > r) r = i + d[i], pos = i;
		ans = std::max(ans, d[i] - 1);
	}
	return ;
}

int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	std::cin >> s;
	t[l++] = '@', t[l++] = '#';
	LL len = s.length();
	for (LL i = 0; i < len; ++i) {
		t[l++] = s[i];
		t[l++] = '#';
	}
	manacher();
	std::cout << ans;
	return 0;
}
2025/7/23 19:27
加载中...