QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278263 | #5065. Beautiful String | hhoppitree# | WA | 1252ms | 200040kb | C++14 | 1.6kb | 2023-12-07 14:24:48 | 2023-12-07 14:24:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5010;
int lcp[N][N];
int F[N][N];
int T,n;
char s[N];
const __int128 P=1e18+9;
__int128 h[N],B=10;
unordered_map<long long,int>M;
int main()
{
cin>>T;
while(T--)
{
cin>>s+1;n=strlen(s+1);
memset(lcp,0,sizeof lcp);
memset(F,0,sizeof F);
for(int i=n;i;--i)
for(int j=n;j;--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 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)
for(int j=1;j<=n;++j)
F[i][j]+=F[i][j-1];
for(int i=1;i<=n;++i)s[i]-='0';
long long ans=0;
for(int d=1;d<=n;++d)
{
int p=1;M.clear();
__int128 up=0,b=1;
for(int i=1;i<=d;++i)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)%P;
// cerr<<"RANGE: "<<i<<" "<<j<<" "<<(long long)up<<" "<<M[up]<<endl;
h[i]=up;
ans+=M[h[i]];
}
}
cout<<ans<<endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 24ms
memory: 199772kb
input:
2 114514 0000000
output:
1 3
result:
ok 2 number(s): "1 3"
Test #2:
score: 0
Accepted
time: 1252ms
memory: 200040kb
input:
11 79380 2483905227 37902399703986576270 39991723655814713848046032694137883815354365954917 5541883522667841718787744915558298207485830622522715211018760095628594390563630840464643840093757297 56530485554219245862513973750218715585679416120445975390556326891488719311495909340757506478400624741858999...
output:
0 0 0 2 4 20 119 113 1086 2128 15166
result:
ok 11 numbers
Test #3:
score: -100
Wrong Answer
time: 802ms
memory: 199944kb
input:
50 11111111111111111111111111111111111111121111111111111111111111111111111111111112111111111121111111111211111121211121111111111111111111111111111211121111111111111111111111111111111111111111111111111112 111111111111111111111111111111111111111111111121111121111111111111111111111111111111111111111111...
output:
1207127 975646 921806 913319 1738140 523590 921284 848294 553347 1456799 472453 1336834 725381 693152 689243 1233223 650978 458408 683843 725488 966713 824591 592917 690513 1359109 914623 547971 458474 789115 894213 695994 1474554 818025 967925 574497 445129 1613731 1595924 635887 1157388 1034543 60...
result:
wrong answer 1st numbers differ - expected: '779344', found: '1207127'