QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#9733 | #801. 回文自动机 | Qingyu | 0 | 2ms | 13820kb | C++20 | 1.7kb | 2021-04-09 22:50:38 | 2021-12-19 11:45:57 |
Judging History
answer
#include <bits/stdc++.h>
const int N = 4e6 + 50;
int len[N], fa[N], ch[N][26], cnt[N], p, tot, lst;
char s[N];
inline void init()
{
s[0] = '$';
tot = -1;
len[++tot] = 0, len[++tot] = -1;
fa[0] = 1;
}
inline int get_fail(int x)
{
while (s[p] != s[p - len[x] - 1]) x = fa[x];
return x;
}
inline void ins(int x)
{
int o = get_fail(lst);
if (!ch[o][x])
{
++tot;
len[tot] = len[o] + 2;
fa[tot] = ch[get_fail(o)][x];
ch[o][x] = tot;
}
lst = ch[o][x];
++cnt[lst];
}
template<int T>
struct fast_io
{
char p[T], *p1, *p2, q[T], *q1, *q2;
fast_io()
{
p1 = p2 = p, q1 = q, q2 = q + T;
}
inline char gc()
{
return p1 == p2 && (p2 = (p1 = p) + fread(p, 1, T, stdin), p1 == p2) ? EOF : *p1 ++;
}
inline void pc(char c)
{
if (q1 == q2)
{
fwrite(q, 1, T, stdout);
q1 = q;
}
*q1++ = c;
}
~fast_io()
{
fwrite(q, 1, q1 - q, stdout);
}
};
fast_io<1024768> io;
inline int read()
{
int res = 0;
char ch;
do ch = io.gc(); while (ch < 48 || ch > 57);
do res = res * 10 + ch - 48, ch = io.gc(); while (ch >= 48 && ch <= 57);
return res;
}
inline void putint(int64_t x)
{
if (x < 0) x = -x;
if (x >= 10) putint(x / 10);
io.pc(48 + x % 10);
}
inline void output(int64_t x, char ch = ' ')
{
putint(x);
io.pc(ch);
}
int main()
{
scanf("%s", s + 1);
init();
int n = strlen(s + 1);
for (int i = 1; i <= n; ++i)
{
p = i;
ins(s[i] - 'a');
}
long long ans = 0;
for (int i = tot; i >= 1; --i)
{
cnt[fa[i]] += cnt[i];
}
for (int i = 1; i <= tot; ++i)
ans = std::max(ans, 1ll * len[i] * len[i] * cnt[i]);
output(ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 13820kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbeffcfgfeedgegdagbgagafbfaaffgfaaebcecfdfccdfdfbefdgddadgagbbefebcecfdfccdegecadfebffgcedfcdcdaaeadeebcedbdagcaagdgcdfbabafbdebgacaabdegecadfebebdbfgegadabbfgeacdgdcgaefccebfeddacbabfeecgbcecegeaabcbdafa...
output:
3978
result:
wrong answer expected '5594', found '3978'
Subtask #2:
score: 0
Skipped