# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205602 | mihai50000 | 회문 (APIO14_palindrome) | C++17 | 73 ms | 40852 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 int long long
struct PalTree {
struct Node {
map<char, int> leg;
int link, len, cnt;
};
vector<Node> T;
int nodes = 2;
int ans = 0;
PalTree(string str) : T(str.size() + 2) {
T[1].link = T[1].len = 0;
T[0].link = T[0].len = -1;
int last = 0;
for (int i = 0; i < (int)str.size(); ++i) {
char now = str[i];
int node = last;
while (now != str[i - T[node].len - 1])
node = T[node].link;
if (T[node].leg.count(now)) {
node = T[node].leg[now];
T[node].cnt += 1;
last = node;
continue;
}
int cur = nodes++;
T[cur].len = T[node].len + 2;
T[node].leg[now] = cur;
int link = T[node].link;
while (link != -1) {
if (now == str[i - T[link].len - 1] && T[link].leg.count(now)) {
link = T[link].leg[now];
break;
}
link = T[link].link;
}
if (link <= 0) link = 1;
T[cur].link = link;
T[cur].cnt = 1;
last = cur;
}
for (int node = nodes - 1; node > 0; --node)
{
T[T[node].link].cnt += T[node].cnt;
ans = max(ans, T[node].cnt * T[node].len);
}
}
};
main()
{
string s;
cin >> s;
PalTree arb(s);
cout << arb.ans << '\n';
}
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... |