QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278495 | #5065. Beautiful String | hhoppitree# | WA | 590ms | 102056kb | C++14 | 1.8kb | 2023-12-07 16:42:53 | 2023-12-07 16:42:53 |
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)
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;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5964kb
input:
2 114514 0000000
output:
1 3
result:
ok 2 number(s): "1 3"
Test #2:
score: -100
Wrong Answer
time: 590ms
memory: 102056kb
input:
11 79380 2483905227 37902399703986576270 39991723655814713848046032694137883815354365954917 5541883522667841718787744915558298207485830622522715211018760095628594390563630840464643840093757297 56530485554219245862513973750218715585679416120445975390556326891488719311495909340757506478400624741858999...
output:
0 0 0 2 4 20 119 112 1083 2123 15124
result:
wrong answer 8th numbers differ - expected: '113', found: '112'