# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
33797 | sinhriv | Palindromes (APIO14_palindrome) | C++14 | 3 ms | 131072 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 eerTree{
static const int Alpabet = 30;
static const int N = 1e6;
struct Node{
int nxt[Alpabet];
int suffix;
int len;
int value;
};
int cnt;
int current;
Node tree[N];
string source;
void addLetter(int pos){
int u = current;
int c = source[pos] - 'a';
while(true){
int len = tree[u].len;
if(pos - len - 1 >= 0 && source[pos - len - 1] == source[pos]){
break;
}
u = tree[u].suffix;
}
if(tree[u].nxt[c] != 0){
++tree[tree[u].nxt[c]].value;
return;
}
tree[u].nxt[c] = ++cnt;
tree[cnt].value = 1;
tree[cnt].len = tree[u].len + 2;
if(tree[cnt].len == 1){
tree[cnt].suffix = 2;
current = cnt;
return;
}
while(true){
u = tree[u].suffix;
int len = tree[u].len;
if(pos - len - 1 >= 0 && source[pos - len - 1] == source[pos]){
tree[cnt].suffix = tree[u].nxt[c];
break;
}
}
current = cnt;
}
void Init(string x){
cnt = current = 2;
source = x;
tree[1].len = -1;
tree[1].suffix = 1;
tree[2].len = 0;
tree[2].suffix = 1;
for(int i = 0; i < source.size(); ++i){
addLetter(i);
}
}
long long calc(){
long long ans = 0;
for(int i = cnt; i >= 1; --i){
ans = max(ans, 1LL * tree[i].value * tree[i].len);
tree[tree[i].suffix].value += tree[i].value;
}
return ans;
}
}f;
int main(){
if(fopen("1.inp", "r")){
freopen("1.inp", "r", stdin);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
f.Init(s);
cout << f.calc();
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... |