This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 303030;
int last, num, child[N][26], len[N], suffLink[N], occ[N];
string s;
void insert(int i)
{
while (s[i - len[last] - 1] != s[i])
last = suffLink[last];
int w = s[i] - 'a', temp = suffLink[last];
while (s[i - len[temp] - 1] != s[i])
temp = suffLink[temp];
if (child[last][w] == 0)
{
child[last][w] = ++num, len[num] = len[last] + 2;
suffLink[num] = (len[num] == 1 ? 0 : child[temp][w]);
}
last = child[last][w], ++occ[last];
}
int main()
{
//freopen("z.inp", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
len[0] = 0, len[1] = -1, last = num = 1, suffLink[0] = suffLink[1] = 1;
cin >> s;
for (int i = 0; i < s.size(); i++)
insert(i);
long long ans = 0;
for (int i = num; i > 1; i--)
{
ans = max(ans, 1ll * len[i] * occ[i]);
occ[suffLink[i]] += occ[i]; //cap nhat nguoc len cho cac nut suffLink
}
cout << ans;
return 0;
}
Compilation message (stderr)
palindrome.cpp: In function 'int main()':
palindrome.cpp:28:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); i++)
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |