QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#772147 | #5065. Beautiful String | OIer_kzc# | WA | 94ms | 101496kb | C++20 | 1.0kb | 2024-11-22 17:12:03 | 2024-11-22 17:12:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
char s[5005];
int lcp[5005][5005],w[5005];
ull sum[5005],mi[5005];
inline bool check(int l1,int r1,int l2,int r2){
return sum[r2+1]-sum[l2]==(sum[r1+1]-sum[l1])*mi[r2-r1];
}
int main(){
int t;cin>>t;
*mi=1;for(int i=1;i<5001;i++) mi[i]=mi[i-1]*11;
while(t--){
cin>>s;
int n=strlen(s);
ull mul=1;
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+mi[i-1]*(s[i-1]-47);
for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) lcp[i][j]=0;
for(int i=n-1;~i;i--) for(int j=n-1;~j;j--) if(s[i]==s[j]) lcp[i][j]=lcp[i+1][j+1]+1;else lcp[i][j]=0;
ll ans=0;
for(int i=0;i<n;i++){
for(int j=i,l=i-1;j<n&&~l;j++,l--) w[j-i+1]=check(l,i-1,i,j);
for(int j=1;j<=n;j++) w[j]+=w[j-1];
for(int j=i+2;j<n;j++){
int l=min({j-i-2,lcp[i][j]-1,i});
ans+=w[l];
}
}
cout<<ans<<endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
2 114514 0000000
output:
1 3
result:
ok 2 number(s): "1 3"
Test #2:
score: -100
Wrong Answer
time: 94ms
memory: 101496kb
input:
11 79380 2483905227 37902399703986576270 39991723655814713848046032694137883815354365954917 5541883522667841718787744915558298207485830622522715211018760095628594390563630840464643840093757297 56530485554219245862513973750218715585679416120445975390556326891488719311495909340757506478400624741858999...
output:
0 0 0 1 4 19 105 104 978 1932 13689
result:
wrong answer 4th numbers differ - expected: '2', found: '1'