QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#772212#5065. Beautiful StringOIer_kzc#WA 104ms101468kbC++20975b2024-11-22 17:32:522024-11-22 17:32:52

Judging History

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

  • [2024-11-22 17:32:52]
  • 评测
  • 测评结果:WA
  • 用时:104ms
  • 内存:101468kb
  • [2024-11-22 17:32:52]
  • 提交

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],w2[5005];
ull sum[5005],mi[5005];
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);
        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]=lcp[l][i]>=j-i+1;
            for(int j=1;j<=n;j++) w2[j]=w[j]*j,w[j]+=w[j-1],w2[j]+=w2[j-1];
            for(int j=i+3;j<n;j++) if(lcp[i][j]){
                int l=min({j-i-2,lcp[i][j]-1,i});
                ans+=(l+1ll)*w[l]-w2[l];
            }
        }
        cout<<ans<<endl;
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

input:

2
114514
0000000

output:

1
3

result:

ok 2 number(s): "1 3"

Test #2:

score: -100
Wrong Answer
time: 104ms
memory: 101468kb

input:

11
79380
2483905227
37902399703986576270
39991723655814713848046032694137883815354365954917
5541883522667841718787744915558298207485830622522715211018760095628594390563630840464643840093757297
56530485554219245862513973750218715585679416120445975390556326891488719311495909340757506478400624741858999...

output:

0
0
0
2
4
20
119
113
1083
2128
15166

result:

wrong answer 9th numbers differ - expected: '1086', found: '1083'