QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278499 | #5065. Beautiful String | hhoppitree# | WA | 1ms | 5720kb | C++14 | 1.8kb | 2023-12-07 16:45:42 | 2023-12-07 16:45:43 |
Judging History
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)
(s[i]==s[j]?(lcp[i][j]=lcp[i+1][j+1]+1):0);
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=P-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;
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5720kb
input:
2 114514 0000000
output:
0 3
result:
wrong answer 1st numbers differ - expected: '1', found: '0'