이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MXN = 300005, SGM = 26;
int n, ts, C[MXN][SGM], len[MXN], link[MXN], cnt[MXN];
char S[MXN];
inline int GetLink(int nw, int i)
{
while (S[i] != S[i - len[nw] - 1])
nw = link[nw];
return (nw);
}
inline int Add(int nw, int i)
{
int ch = S[i] - 'a';
nw = GetLink(nw, i);
if (!C[nw][ch])
{
++ ts;
len[ts] = len[nw] + 2;
link[ts] = C[GetLink(link[nw], i)][ch];
C[nw][ch] = ts;
}
return (C[nw][ch]);
}
int main()
{
scanf("%s", S);
n = strlen(S);
len[1] = -1; ts = 1;
link[0] = link[1] = 1;
int nw = 1;
for (int i = 1; i <= n; i++)
nw = Add(nw, i - 1), cnt[nw] ++;
long long Mx = 0;
for (int i = ts; i >= 0; i--)
cnt[link[i]] += cnt[i], Mx = max(Mx, 1LL * cnt[i] * len[i]);
return !printf("%lld\n", Mx);
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'int main()':
palindrome.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", S);
~~~~~^~~~~~~~~
# | 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... |