QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44838 | #801. 回文自动机 | He_Ren# | 0 | 4ms | 6308kb | C++14 | 1.2kb | 2022-08-22 08:50:02 | 2022-08-22 08:50:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e6 + 5;
namespace PAM
{
int son[MAXN][26], len[MAXN], fail[MAXN], pcnt, s[MAXN], n;
int insert(int u,int c)
{
while(s[n - len[u] - 1] != s[n]) u = fail[u];
if(son[u][c]) return son[u][c];
int v = ++pcnt; len[v] = len[u] + 2;
int w = fail[u];
while(s[n - len[w] - 1] != s[n]) w = fail[w];
fail[v] = w;
son[u][c] = v;
return v;
}
int f[MAXN], bak[MAXN], seq[MAXN];
ll build(char *_s,int _n)
{
pcnt = 1; len[0] = 0; len[1] = -1; fail[0] = 1; n = 0; s[0] = -1;
int lst = 0;
for(int i=1; i<=_n; ++i)
{
s[++n] = _s[i] - 'a';
lst = insert(lst, s[n]);
++f[lst];
}
for(int i=2; i<=n; ++i)
++bak[len[i]];
for(int i=1; i<=n; ++i)
bak[i] += bak[i-1];
for(int i=n; i>=2; --i)
seq[bak[len[i]]--] = i;
ll ans = 0;
for(int i=n; i>=2; --i)
{
int u = seq[i];
f[fail[u]] += f[u];
ans = max(ans, (ll)f[u] * len[u] * len[u]);
}
return ans;
}
}
char s[MAXN];
int main(void)
{
scanf("%s",s+1);
int n = strlen(s+1);
ll ans = PAM :: build(s, n);
printf("%lld\n",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: 4ms
memory: 6308kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
4772
result:
wrong answer expected '5594', found '4772'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%