# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112437 | Akashi | Palindromes (APIO14_palindrome) | C++14 | 111 ms | 66732 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;
struct Node{
vector <int> v;
int son[26];
int num, length, link;
};
Node PalTree[300005];
char s[300005];
void initialize_tree(){
PalTree[1].length = -1; PalTree[1].link = 1;
PalTree[2].length = 0; PalTree[2].link = 1;
}
int Last = 2, tree_size = 2;
void add_letter(int pos){
char ch = s[pos] - 'a';
while(true){
if(pos - PalTree[Last].length - 1 >= 0 && s[pos] == s[pos - PalTree[Last].length - 1]) break ;
Last = PalTree[Last].link;
}
if(PalTree[Last].son[ch]){
PalTree[PalTree[Last].son[ch]].num++;
Last = PalTree[Last].son[ch];
return ;
}
int cur = ++tree_size;
PalTree[Last].son[ch] = cur;
PalTree[cur].length = PalTree[Last].length + 2;
PalTree[cur].num = 1;
if(Last == 1){
PalTree[2].v.push_back(cur);
PalTree[cur].link = 2;
Last = cur;
return ;
}
while(true){
Last = PalTree[Last].link;
if(pos - PalTree[Last].length - 1 >= 0 && s[pos] == s[pos - PalTree[Last].length - 1]){
PalTree[cur].link = PalTree[Last].son[ch];
PalTree[PalTree[cur].link].v.push_back(cur);
break ;
}
}
Last = cur;
}
long long Sol = 0;
void dfs(int nod = 2){
for(auto it : PalTree[nod].v){
dfs(it);
PalTree[nod].num += PalTree[it].num;
}
Sol = max(Sol, 1LL * PalTree[nod].length * PalTree[nod].num);
}
int main()
{
// freopen("palindrome.in", "r", stdin);
// freopen("palindrome.out", "w", stdout);
initialize_tree();
scanf("%s", s);
int L = strlen(s);
for(int i = 0; i < L ; ++i) add_letter(i);
dfs();
printf("%lld", Sol);
return 0;
}
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... |