# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
621139 | socpite | Palindromes (APIO14_palindrome) | C++14 | 63 ms | 66624 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 f first
#define s second
typedef long long ll;
const int maxn = 3e5+5;
int cnt = 2;
int lnk[maxn], go[maxn][26], len[maxn];
ll dp[maxn];
ll ans = 0;
vector<int> tree[maxn];
string str;
void dfs(int x){
for(auto v: tree[x]){
dfs(v);
dp[x]+=dp[v];
}
ans = max(ans, dp[x]*len[x]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> str;
str = '#'+str;
len[0]=-1;
len[1]=0;
int crr = 1;
for(int i = 1; i < str.length(); i++){
int id = str[i]-'a';
while(crr && str[i] != str[i-len[crr]-1])crr = lnk[crr];
if(go[crr][id])crr = go[crr][id];
else{
int tmp = lnk[crr];
while(tmp && str[i] != str[i-len[tmp]-1])tmp = lnk[tmp];
if(!go[tmp][id])lnk[cnt]=1;
else lnk[cnt]=go[tmp][id];
go[crr][id]=cnt;
len[cnt]=len[crr]+2;
crr = cnt;
cnt++;
}
dp[crr]++;
}
for(int i = 1; i < cnt; i++)tree[lnk[i]].push_back(i);
dfs(0);
cout << ans;
}
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... |