# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41655 | kingpig9 | Palindromes (APIO14_palindrome) | C++11 | 54 ms | 42332 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;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 300763;
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
struct palindromic_tree {
int slen; //total length of string
char str[MAXN];
int len[MAXN];
int nnodes;
int link[MAXN], nxt[MAXN][26];
int last;
int cnt[MAXN]; //count of the node
vector<int> adj[MAXN];
palindromic_tree() {
str[0] = -1;
slen = 1;
link[0] = 1;
len[1] = -1;
nnodes = 2;
}
int getlink (int x) {
while (str[slen - 2 - len[x]] != str[slen - 1]) {
//debug("str[%d] != str[%d]\n", slen - 2 - len[x], slen - 1);
x = link[x];
}
//debug("finally! str[%d] == str[%d]\n", slen - 2 - len[x], slen - 1);
return x;
}
void add (char ch) {
ch -= 'a';
str[slen++] = ch;
last = getlink(last);
if (!nxt[last][ch]) {
len[nnodes] = len[last] + 2;
link[nnodes] = nxt[getlink(link[last])][ch]; //link with next char added to end
nxt[last][ch] = nnodes;
nnodes++;
}
last = nxt[last][ch];
}
} tr;
int N;
char S[MAXN];
int main() {
scanf("%s", S);
N = strlen(S);
for (int i = 0; i < N; i++) {
tr.add(S[i]);
tr.cnt[tr.last]++;
}
for (int i = tr.nnodes - 1; i > 1; i--) {
tr.cnt[tr.link[i]] += tr.cnt[i];
}
ll ans = 0;
for (int i = 2; i < tr.nnodes; i++) {
ans = max(ans, ll(tr.len[i]) * tr.cnt[i]);
}
printf("%lld\n", 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... |