이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 303030;
struct nut
{
int len = 0, occ = 0, suffLink = 0, child[26];
};
vector<nut> Tree;
char s[N];
int last;
void initPalinTree()
{
Tree.emplace_back(), Tree.emplace_back();
Tree[1].len = -1, Tree[0].suffLink = Tree[1].suffLink = 1;
last = 0;
}
bool insert(int i)
{
//Tim nut X to nhat thoa man
while (s[i - Tree[last].len - 1] != s[i])
last = Tree[last].suffLink;
//Tim nut ma suffLink se tro toi
int w = s[i] - 'a', tmp = Tree[last].suffLink;
while (s[i - Tree[tmp].len - 1] != s[i])
tmp = Tree[tmp].suffLink;
//Them moi : Neu nut nay chua co trong cay
if (Tree[last].child[w] == 0)
{
Tree[last].child[w] = Tree.size();
Tree.emplace_back();
Tree.back().len = Tree[last].len + 2;
Tree.back().suffLink = (Tree.back().len == 1 ? 0 : Tree[tmp].child[w]);
}
last = Tree[last].child[w];
Tree[last].occ++;
return 1;
}
int main()
{
//freopen("z.inp", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
initPalinTree();
cin >> s;
for (int i = 0; i < strlen(s); i++)
insert(i);
long long ans = 0;
for (int i = Tree.size() - 1; i >= 2; i--)
{
ans = max(ans, 1ll * Tree[i].len * Tree[i].occ);
Tree[Tree[i].suffLink].occ += Tree[i].occ;
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'int main()':
palindrome.cpp:47:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < strlen(s); i++)
~~^~~~~~~~~~~
# | 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... |