QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#772199#5065. Beautiful StringOIer_kzc#WA 83ms101460kbC++201.0kb2024-11-22 17:26:132024-11-22 17:26:13

Judging History

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

  • [2024-11-22 17:26:13]
  • 评测
  • 测评结果:WA
  • 用时:83ms
  • 内存:101460kb
  • [2024-11-22 17:26:13]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

2
114514
0000000

output:

1
3

result:

ok 2 number(s): "1 3"

Test #2:

score: -100
Wrong Answer
time: 83ms
memory: 101460kb

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'