# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205591 | mihai50000 | 회문 (APIO14_palindrome) | C++17 | 54 ms | 30356 KiB |
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;
#define int long long
struct PalTree
{
struct Node
{
map <char, int> next;
int link;
int len;
int cnt;
};
vector <Node> T;
int n = 2;
int ans = 0;
PalTree(string str) : T(str.size() + 2)
{
T[1].link = T[1].len = 0;
T[0].link = T[0].len = -1;
int last = 0;
int m = str.size();
for(int i = 0; i < m; ++i)
{
char ch = str[i];
int nod = last;
while(ch != str[i - 1 - T[nod].len])
nod = T[nod].link;
if(T[nod].next.count(ch))
{
nod = T[nod].next[ch];
T[nod].cnt++;
last = nod;
continue;
}
int act = n++;
T[act].len = T[nod].len + 2;
T[nod].next[ch] = act;
int link = T[nod].link;
while(link != -1)
{
if(ch == str[i - T[link].len - 1] && T[link].next.count(ch))
{
link = T[link].next[ch];
break;
}
link = T[link].link;
}
if(link <= 0)
link = 1;
T[act].link = 1;
T[act].cnt = 1;
last = act;
}
for(int i = n - 1; i > 0; --i)
{
T[T[i].link].cnt += T[i].cnt;
ans = max(ans, T[i].cnt * T[i].len);
}
for(int i = 0; i < n; ++i)
{
ans = max(ans, T[i].cnt * T[i].len);
}
}
};
main()
{
string s;
cin >> s;
PalTree arb(s);
cout << arb.ans << '\n';
}
Compilation message (stderr)
# | 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... |