# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30165 | Andrei1998 | Palindromes (APIO14_palindrome) | C++14 | 1000 ms | 79612 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;
const int NMAX = 2 * 300000 + 5;
inline int toInt(char ch) {
if (ch == '#')
return 0;
else
return ch - 'a' + 1;
}
string str;
int nodes;
int alf[NMAX][27];
int h[NMAX];
int father[NMAX];
int ext[NMAX];
int whichNode[NMAX];
int cnt[NMAX];
long long int ans = 1;
void dfs(int node, int realH) {
for (int i = 0; i < 27; ++ i)
if (alf[node][i]) {
dfs(alf[node][i], realH + (i > 0) * (1 + (node > 1)));
cnt[node] += cnt[alf[node][i]];
}
ans = max(ans, 1LL * realH * cnt[node]);
}
int main()
{
//freopen("data.in", "r", stdin);
cin >> str;
string str2 = "#";
for (auto it: str) {
str2 += it;
str2 += '#';
}
str = str2;
str = " " + str;
int N = str.size() - 1;
++ nodes;
int center = 0;
for (int i = 1; i <= N; ++ i) {
int node = 1;
int l = 0;
while (i - l >= 1 && i + l <= N && str[i - l] == str[i + l]) {
if (!alf[node][toInt(str[i - l])]) {
alf[node][toInt(str[i - l])] = ++ nodes;
h[nodes] = 1 + h[node];
father[nodes] = node;
}
node = alf[node][toInt(str[i - l])];
++ l;
}
ext[i] = l;
whichNode[i] = node;
++ cnt[node];
}
dfs(1, 0);
cout << ans << '\n';
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... |