제출 #543154

#제출 시각아이디문제언어결과실행 시간메모리
543154Sohsoh84회문 (APIO14_palindrome)C++17
100 / 100
31 ms35088 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;
const ll SIG = 26;

int nxt[MAXN][SIG], F[MAXN], len[MAXN], sz, v, cnt[MAXN];
string s;

inline void add(int pos) {
	while (pos - 1 - len[v] < 0 || s[pos] != s[pos - 1 - len[v]])
		v = F[v];

	int c = s[pos] - 'a';
	if (!nxt[v][c]) {
		nxt[v][c] = ++sz;
		len[sz] = len[v] + 2;

		v = F[v];
		while (s[pos] != s[pos - 1 - len[v]]) v = F[v];
		if (len[sz] > 1) F[sz] = nxt[v][c];
		else F[sz] = 1;

		v = sz;
		cnt[sz]++;
	} else {
		v = nxt[v][c];
		cnt[v]++;
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	sz = v = 1;
	len[0] = -1;
	len[1] = F[1] = 0;
	
	cin >> s;
	for (int i = 0; i < int(s.size()); i++)
		add(i);

	ll ans = 0;
	for (int i = sz; i > 0; i--) {	
		ans = max(ans, 1ll * cnt[i] * len[i]);
		cnt[F[i]] += cnt[i];
	}

	cout << ans << endl;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...