| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 331149 | couplefire | Palindromes (APIO14_palindrome) | C++17 | 59 ms | 40552 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 MAXN 300005
template<int SZ> struct PalTree{
static const int sigma = 26;
int s[SZ], len[SZ], link[SZ], to[SZ][sigma], oc[SZ];
int n, last, sz;
PalTree(){
s[n++] = -1;
link[0] = 1;
len[1] = -1;
sz = 2;
}
int getLink(int v){
while(s[n-len[v]-2] != s[n-1]) v = link[v];
return v;
}
void add(int c){
s[n++] = c;
last = getLink(last);
if(!to[last][c]){
len[sz] = len[last]+2;
link[sz] = to[getLink(link[last])][c];
to[last][c] = sz++;
}
last = to[last][c];
oc[last]++;
}
void prop(){
vector<pair<int, int>> v;
for(int i = 2; i<sz; i++) v.push_back({len[i], i});
sort(v.begin(), v.end()); reverse(v.begin(), v.end());
for(auto a : v) oc[link[a.second]] += oc[a.second];
}
};
PalTree<MAXN> tree;
string s;
int main(){
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> s;
for(int i = 0; i<s.length(); i++){
tree.add(s[i]-'a');
}
tree.prop();
long long ans = 0;
for(int i = 2; i<tree.sz; i++){
ans = max(ans, 1ll*tree.len[i]*tree.oc[i]);
}
cout << ans << endl;
}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... | ||||
