QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#364229 | #5065. Beautiful String | Baiyu0123 | WA | 113ms | 3736kb | C++14 | 851b | 2024-03-24 13:06:11 | 2024-03-24 13:06:11 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+100;
char a[maxn],b[maxn];
int z[maxn],cnt[maxn];
string s;
void calc(int n) {
int l=0,r=0;
z[0]=n;
for (int i=1;i<n;i++) {
int x=0;
if (i<=r) x=min(z[i-l],r-i);
while (i+x<n&&b[x]==b[i+x]) x++;
if (i+x-1>r) l=i,r=i+x-1;
z[i]=x;
}
}
int main() {
int T;cin>>T;
while (T--) {
cin>>s;int n=s.size();ll ans=0;
for (int st=1;st<n;st++) {
int i=0;
for (;st+i<n;i++) b[i]=s[st+i];
b[i++]='#';
for (int j=0;j<st;j++) b[i++]=s[j];
calc(n+1);
for (int i=1;i<=st;i++) {
if (z[n+1-i]==i) cnt[i]=1;
}
for (int i=1;i<=n;i++) cnt[i]+=cnt[i-1];
for (int i=1;i+st<n;i++) {
int x=max(min(z[i]-1,i-2),0);
ans+=cnt[x];
}
for (int i=1;i<=n;i++) cnt[i]=0;
}
cout<<ans<<endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3704kb
input:
2 114514 0000000
output:
1 3
result:
ok 2 number(s): "1 3"
Test #2:
score: -100
Wrong Answer
time: 113ms
memory: 3736kb
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'