# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
745144 | ACE_ | Palindromes (APIO14_palindrome) | C++14 | 39 ms | 45168 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>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int cnt[N], in[N], last = 0, cur = 1;
struct eer {
int e[26], suf, sz;
} t[N];
vector<int> V[N];
string s;
void add(int i) {
while(true) {
if(s[i] == s[i - t[last].sz - 1]) {
if(t[last].e[s[i] - 'a']) {
last = t[last].e[s[i] - 'a'];
++cnt[last];
return;
}
t[last].e[s[i] - 'a'] = ++cur;
t[cur].sz = t[last].sz + 2;
cnt[cur] = 1;
break;
}
last = t[last].suf;
}
int id = t[last].suf;
if(last == 0) {
t[cur].suf = 1;
last = cur;
return;
}
last = cur;
while(true) {
if(s[i] == s[i - t[id].sz - 1] || id == 1) {
t[cur].suf = t[id].e[s[i] - 'a'];
V[cur].push_back(t[id].e[s[i] - 'a']);
++in[t[id].e[s[i] - 'a']];
return;
}
id = t[id].suf;
}
}
main(){
cin >> s;
t[0].sz = -1;
t[1].sz = 0;
cur = 1; last = cur;
for(int i = 0; i < s.size(); i++) {
add(i);
}
queue<int> q;
for(int i = 1; i <= cur; i++) {
if(!in[i]) q.push(i);
}
int ans = 0;
while(q.size()) {
int x = q.front();
q.pop();
ans = max(ans, t[x].sz * cnt[x]);
for(int i = 0; i < V[x].size(); i++) {
cnt[V[x][i]] += cnt[x];
--in[V[x][i]];
if(!in[V[x][i]]) q.push(V[x][i]);
}
}
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... |