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 <iostream>
#include <vector>
#include <algorithm>
#include <set>
typedef long long ll;
using namespace std;
const int maxn = 3e5 + 5, abc = 26;
//const int maxn = 15, abc = 26;
struct node
{
int nx[abc], len, link, cnt; // hrany dopredu, dlzka, spatna hrana, pocet kratov kedy som videla tento palindrom
} vr[maxn];
string s;
int suf, nd = 2;
void add(int i, int ch)
{
while (i - vr[suf].len - 1 < 0 || s[i - vr[suf].len - 1] != s[i])
{
suf = vr[suf].link;
}
if (vr[suf].nx[ch])
{
suf = vr[suf].nx[ch];
vr[suf].cnt++;
return;
}
nd++;
vr[nd].len = vr[suf].len + 2;
vr[suf].nx[ch] = nd;
int j = vr[suf].link;
suf = nd;
vr[suf].cnt++;
if (vr[suf].len == 1)
{
vr[suf].link = 2;
return;
}
while (i - vr[j].len - 1 < 0 || s[i - vr[j].len - 1] != s[i])
{
j = vr[j].link;
}
vr[suf].link = vr[j].nx[ch];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
vr[1].link = 1, vr[1].len = -1;
vr[2].link = 1, vr[2].len = 0;
suf = 2;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i++)
add(i, s[i] - 'a');
ll ans = 0;
for (int i = nd; i > 0; i--)
{
//cout << vr[i].cnt << "*" << vr[i].len << "\n";
ans = max(ans, vr[i].cnt * 1ll * vr[i].len);
vr[vr[i].link].cnt += vr[i].cnt;
}
cout << ans << "\n";
return 0;
}
# | 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... |