QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#278493#5065. Beautiful Stringhhoppitree#Compile Error//C++141.8kb2023-12-07 16:42:322023-12-07 16:42:32

Judging History

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

  • [2023-12-07 16:42:32]
  • 评测
  • [2023-12-07 16:42:32]
  • 提交

answer

#pragma optimize("Ofast")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
const int N=5010;
short lcp[N][N];
short F[N][N];
int T,n;
char s[N];
const int P=1e9+7,B=233;
long long h[N];
gp_hash_table<int,int>M;
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin>>T;
    while(T--)
    {
        cin>>s+1;n=strlen(s+1);
        for(int i=1;i<=n+1;++i)
            memset(lcp[i],0,sizeof(short)*(n+5)),
            memset(F[i],0,sizeof(short)*(n+5));
        for(int i=n;i;--i)
            for(int j=1;j<=n;++j)
                lcp[i][j]=(lcp[i+1][j+1]+1)*(s[i]==s[j]);
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=n&&j<=i&&j+i-1<=n;++j)
                F[i][j]=lcp[i][i-j]>=j;
            for(int j=1;j<=n;++j)
                F[i][j]+=F[i][j-1];
        }
        // for(int i=1;i<=n;++i)
        //     for(int j=1;j<=n;++j)
        //         cerr<<"F["<<i<<"]["<<j<<"]="<<F[i][j]<<endl;
        for(int i=1;i<=n;++i)s[i]-='0';
        long long ans=0,b=1;
        for(int d=1;d<=n;++d)
        {
            int p=1;M.clear();
            long long up=0;
            b=b*B%P;
            for(int i=1;i<d;++i)up=(up*B+s[i])%P;
            for(int i=1,j=d;j<=n;++i,++j)
            {
                while(p<i-d)
                {
                    M[h[p]]+=F[p][d-1];
                    // cerr<<"ADD: "<<p<<" "<<(long long)h[p]<<" "<<F[p][d-1]<<endl;
                    ++p;
                }
                up=(up*B+s[j])%P;
                if(i!=1)up=(up-b*s[i-1]+P)%P;
                // cerr<<"RANGE: "<<i<<" "<<j<<" "<<(long long)up<<" "<<M[up]<<endl;
                h[i]=up;
                if(M.find(h[i])!=M.end())ans+=M[h[i]];
            }
        }
        cout<<ans<<endl
    }
}

详细

answer.code: In function ‘int main()’:
answer.code:60:24: error: expected ‘;’ before ‘}’ token
   60 |         cout<<ans<<endl
      |                        ^
      |                        ;
   61 |     }
      |     ~