QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#478729 | #801. 回文自动机 | liuhengxi | 0 | 0ms | 5756kb | C++14 | 813b | 2024-07-15 10:39:45 | 2024-07-15 10:39:45 |
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
#define F(i,l,r) for(int i=(l),i##_end=(r);i<i##_end;++i)
using namespace std;
typedef long long ll;
constexpr int N=1e6+5;
struct node
{
int tr[26],len,fail;
}a[N];
int n,ind,cur,occ[N];
char s[N];
int main()
{
scanf("%s",s);
n=(int)strlen(s);
a[0].fail=1;
a[1].len=-1;
ind=2;
F(i,0,n)
{
if(a[cur].len==i)cur=a[cur].fail;
while(s[i]!=s[i-a[cur].len-1])cur=a[cur].fail;
int x=s[i]-'a';
if(!a[cur].tr[x])
{
int u=ind++;
a[u].len=a[cur].len+2;
a[u].fail=cur!=1?a[a[cur].fail].tr[x]:0;
a[cur].tr[x]=u;
}
cur=a[cur].tr[x];
++occ[cur];
}
for(int i=ind;--i>1;)occ[a[i].fail]+=occ[i];
ll ans=0;
F(i,2,ind)ans=max(ans,(ll)occ[i]*a[i].len*a[i].len);
printf("%lld\n",ans);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5756kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
5195
result:
wrong answer expected '5594', found '5195'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%