QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125941#801. 回文自动机myee#0 0ms69504kbC++114.4kb2023-07-17 23:04:282023-07-17 23:04:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-17 23:04:31]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:69504kb
  • [2023-07-17 23:04:28]
  • 提交

answer

// 那就是希望。
// 即便需要取模,也是光明。

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
// Heaven and Earth... My guiding star...
// Akira Complex R.I.P.
// uint SA[1000005],Rank[1000005],H[1000005],n;chr C[1000005];
// voi build()
// {
    // for(uint i=0;i<n;i++)SA[i]=i;
    // std::sort(SA,SA+n,[&](uint a,uint b){return C[a]<C[b];});
    // for(uint i=0;i<n;i++)Rank[SA[i]]=i&&C[SA[i]]==C[SA[i-1]]?Rank[SA[i-1]]:i;
    // for(uint h=0;(1u<<h)<n;h++)
    // {
        // static uint Cnt[1000005];
        // for(uint i=0;i<(1u<<h);i++)H[i]=i+n-(1u<<h);
        // for(uint i=0,j=1u<<h;i<n;i++)if(SA[i]>=(1u<<h))H[j++]=SA[i]-(1u<<h);
        // for(uint i=0;i<n;i++)Cnt[i]=0;
        // for(uint i=0;i<n;i++)Cnt[Rank[i]]++;
        // for(uint i=1;i<n;i++)Cnt[i]+=Cnt[i-1];
        // for(uint i=n-1;~i;i--)SA[--Cnt[Rank[H[i]]]]=H[i];
        // bol ok=true;
        // for(uint i=0;i<n;i++)H[SA[i]]=i&&Rank[SA[i-1]]==Rank[SA[i]]&&(SA[i-1]+(1u<<h)<n?Rank[SA[i-1]+(1u<<h)]:-1u)
                                                        // ==(SA[i]+(1u<<h)<n?Rank[SA[i]+(1u<<h)]:-1u)?(ok=false,H[SA[i-1]]):i;
        // for(uint i=0;i<n;i++)Rank[i]=H[i];
        // if(ok)break;
    // }
    // for(uint i=0,j=0;i<n;i++)
    // {
        // if(j)j--;
        // if(Rank[i])while(i+j<n&&SA[Rank[i]-1]+j<n&&C[i+j]==C[SA[Rank[i]-1]+j])j++;
        // H[Rank[i]]=j;
    // }
// }
// uint Fath[2000005],Dep[2000005],m;
// std::vector<uint>Son[2000005];
// voi build2()
// {
    // m=n+1,Fath[n]=-1;for(uint i=0;i<=n;i++)Dep[i]=n-i;
    // static uint S[1000005],tp;S[0]=n,tp=1;
    // for(uint i=0;;i++)
    // {
    	// uint lst=-1;
    	// while(Dep[S[tp-1]]>H[i])
    	// {
    		// tp--;if(~lst)Fath[lst]=S[tp];
    		// lst=S[tp];
    	// }
    	// if(Dep[S[tp-1]]<H[i])Dep[S[tp++]=m++]=H[i];
    	// if(~lst)Fath[lst]=S[tp-1];
    	// if(i<n)S[tp++]=SA[i];else break;
    // }
    // for(uint i=0;i<m;i++)if(i!=n)Son[Fath[i]].push_back(i);
// }
chr S[2000005];uint M[2000005],R[2000005],Son[27][2000005],Fath[21][2000005],Dep[2000005],Cnt[2000005],tp;
uint NewNode(uint f)
{
	Dep[tp]=Dep[f]+1,Fath[0][tp]=f;for(uint i=0;i<=26;i++)Son[i][tp]=-1;
	for(uint h=1;Dep[tp]>>h;h++)Fath[h][tp]=Fath[h-1][Fath[h-1][tp]];
	return tp++;
}
uint kthF(uint p,uint k)
{
	while(k)p=Fath[__builtin_ctz(k)][p],k^=lowbit(k);
	return p;
}
inline uint GetSon(uint p,chr c){uint o=c=='$'?26:c-'a';return~Son[o][p]?Son[o][p]:Son[o][p]=NewNode(p);}
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
	static chr C[1000005];uint n=0;
    scanf("%s",C);while(C[n])S[n<<1]='$',S[n<<1|1]=C[n],n++;
    S[n<<1]='$';//build(),build2();
    tp=1;for(uint i=0;i<=26;i++)Son[i][0]=-1;
    Cnt[R[0]=GetSon(0,'$')]++;
    for(uint i=1,j=0;i<=n*2;i++)
    {
    	M[i]=i<j+M[j]?std::min(M[j*2-i],j+M[j]-i):0;
    	R[i]=i<j+M[j]?kthF(R[j*2-i],M[j]-M[i]):GetSon(0,S[i]);
    	while(M[i]<i&&M[i]+i<n*2&&S[i-M[i]-1]==S[i+M[i]+1])M[i]++,R[i]=GetSon(R[i],S[i+M[i]]);
    	Cnt[R[i]]++;
    	if(i+M[i]>j+M[j])j=i;
    }
    // for(uint i=0;i<=n*2;i++)
    // {
    	// printf("%2u ",R[i]);
    	// for(uint j=0;j<=M[i];j++)putchar(S[i+j]);
    	// putchar('\n');
    // }
    // for(uint i=0;i<tp;i++)for(uint j=0;j<=26;j++)if(~Son[j][i])printf("%u %u %c\n",i,Son[j][i],j==26?'$':(chr)('a'+j));
    for(uint i=tp-1;i;i--)Cnt[Fath[0][i]]+=Cnt[i];
    ullt ans=0;
    for(uint i=1;i<tp;i++)_max(ans,(Dep[i]-1llu)*(Dep[i]-1llu)*Cnt[i]);
    printf("%llu\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: 0ms
memory: 69504kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

4188

result:

wrong answer expected '5594', found '4188'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%