QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#706624 | #6567. Repetitive String Invention | ucup-team902# | TL | 356ms | 21472kb | C++17 | 1019b | 2024-11-03 12:41:14 | 2024-11-03 12:41:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=800;
const int g=27,mod=998244353;
int n;
char s[N+5];
int hv[N+5][N+5];
unordered_map<int,int> cnt[N+5],cnt2[N+5];
ll ans;
int main(){
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++){
hv[i][j]=(1ll*hv[i][j-1]*g+s[j]-'a'+1)%mod;
for(int k=1;k<=i;k++)
cnt[k][hv[i][j]]++;
for(int k=j;k<=n;k++)
cnt2[k][hv[i][j]]++;
}
for(int d=1;d<=n/2;d++){
for(int i=1;i<=n;i++){
for(int j=i+d-1;j<=n&&j-i+1<2*d;j++){
if(hv[i][j-d]==hv[i+d][j])
ans+=cnt[j+1][hv[j-d+1][i+d-1]];
}
}
for(int i=1;i<=n;i++)
for(int j=i+d;j<=n&&j-i+1<2*d;j++){
if(hv[i][j-d]==hv[i+d][j])
ans+=cnt2[i-1][hv[j-d+1][i+d-1]];
}
}
printf("%lld\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3936kb
input:
aaaa
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 0ms
memory: 6024kb
input:
axabxbcxcdxd
output:
22
result:
ok single line: '22'
Test #3:
score: 0
Accepted
time: 356ms
memory: 13744kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
536006700
result:
ok single line: '536006700'
Test #4:
score: 0
Accepted
time: 346ms
memory: 21472kb
input:
abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...
output:
136016600
result:
ok single line: '136016600'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
a
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
ab
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3920kb
input:
aa
output:
1
result:
ok single line: '1'
Test #8:
score: -100
Time Limit Exceeded
input:
bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...