이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 303030;
int last, num, child[N][26], len[N], suffLink[N], occ[N];
string s;
void insert(int i)
{
while (s[i - len[last] - 1] != s[i])
last = suffLink[last];
int w = s[i] - 'a', temp = suffLink[last];
while (s[i - len[temp] - 1] != s[i])
temp = suffLink[temp];
if (child[last][w] == 0)
{
child[last][w] = ++num, len[num] = len[last] + 2;
suffLink[num] = (len[num] == 1 ? 0 : child[temp][w]);
}
last = child[last][w], ++occ[last];
}
int main()
{
//freopen("z.inp", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
len[0] = 0, len[1] = -1, last = num = 1, suffLink[0] = suffLink[1] = 1;
cin >> s;
for (int i = 0; i < s.size(); i++)
insert(i);
long long ans = 0;
for (int i = num; i > 1; i--)
{
ans = max(ans, 1ll * len[i] * occ[i]);
occ[suffLink[i]] += occ[i]; //cap nhat nguoc len cho cac nut suffLink
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'int main()':
palindrome.cpp:28:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); 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... |