QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791876#801. 回文自动机11d10xy0 0ms10204kbC++14910b2024-11-28 21:31:422024-11-28 21:31:43

Judging History

你现在查看的是最新测评结果

  • [2024-11-28 21:31:43]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:10204kb
  • [2024-11-28 21:31:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64=long long;
int n;
char str[1000010];
namespace am{
int ch[1000010][26],len[1000010],lnk[1000010],cnt[1000010],tot,lst;
vector<int>s;
void init(){
   len[0]=-1,lnk[0]=0;
   len[1]=0,lnk[1]=0;
   tot=1,lst=1,s={-1};
}
void extend(int c){
   s.push_back(c);
   int u=lst;
   for(;rbegin(s)[len[u]+1]!=c;u=lnk[u]);
   int&v=ch[u][c];
   if(!v){
      v=++tot,len[v]=len[u]+2;
      int p=lnk[u];
      for(;p&&!ch[p][c];p=lnk[p]);
      if(p)lnk[v]=ch[p][c];
      else lnk[v]=1;
   }lst=v,cnt[v]++;
}
i64 answer(){
   i64 res=0;
   for(int i=tot;i>=1;i--)cnt[lnk[i]]+=cnt[i];
   for(int i=1;i<=tot;i++)res=max(res,cnt[i]*1ll*len[i]*len[i]);
   return res;
}
}
int main(){
   scanf("%s",str+1),n=strlen(str+1);
   am::init();
   for(int i=1;i<=n;i++)am::extend(str[i]-'a');
   printf("%lld",am::answer());
   return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10204kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

6576

result:

wrong answer expected '5594', found '6576'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%