QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#791891#801. 回文自动机11d10xy0 2ms8140kbC++14901b2024-11-28 21:45:122024-11-28 21:45:13

Judging History

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

  • [2024-11-28 21:45:13]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:8140kb
  • [2024-11-28 21:45:12]
  • 提交

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[1]=-1;
   len[2]=0,lnk[2]=1;
   tot=2,lst=2,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]=2;
   }lst=v,cnt[v]++;
}
i64 answer(){
   i64 res=0;
   for(int i=tot;i>=2;i--)cnt[lnk[i]]+=cnt[i];
   for(int i=2;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;
}

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: 8140kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

6132

result:

wrong answer expected '5594', found '6132'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%