QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#516920 | #6567. Repetitive String Invention | ucup-team2307# | WA | 83ms | 42496kb | C++20 | 2.8kb | 2024-08-13 00:08:49 | 2024-08-13 00:08:49 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
//#define int ll
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N = 808;
ull hf(ull a, ull b)
{
return 7*((53*a)^(21*b)) + 13*((97*a)^(33*b));
}
int n;
ull h[N][N];
vector<int> q[N][N];
vector<int> qp[N][N];
int ps[N];
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
{
string s;
cin>>s;
// s = string(800, 'c');
n = s.size();
for (int i=0; i<n; i++)
{
ull a = 911;
for (int j=i; j<n; j++)
a = hf(a, s[j]-'a'+777), h[i][j] = a;
}
}
for (int i=0; i<n; i++)
for (int j=i; j<n; j++)
for (int l=(j-i+1+1)/2; l<=min(j-i+1, n/2); l++)
{
int ex = j-(i+l-1);
if (ex > 0 && h[i][i+ex-1] != h[j-ex+1][j])
continue;
int lt = l-ex;
if (lt <= 0)
continue;
if (j+1+lt-1 < n)
q[lt][i+l-lt].pb(j+1);
if (i-lt>=0 && l!=j-i+1)
qp[lt][i+l-lt].pb(i-lt);
// cout<<i<<" "<<j<<" "<<l<<" "<<ex<<" "<<lt<<" "<<i+l-lt<<" "<<j+1<<"\n";
}
ll ans = 0;
// for (int i=0; i<n; i++)
// for (int j=i; j<n; j++)
// cout<<i<<" "<<j<<" "<<h[i][j]<<"\n";
// for (int l=1; l<=n/2; l++)
// for (int i=0; i<n; i++)
// for (int j : q[l][i])
// {
// for (int r=j; r<=n-l; r++)
// if (h[i][i+l-1] == h[r][r+l-1])
// ans++;
// cout<<l<<" "<<i<<" "<<j<<" "<<ans<<"\n";
// }
// for (int l=1; l<=n/2; l++)
// for (int i=0; i<n; i++)
// for (int j : qp[l][i])
// {
// for (int r=0; r<=j; r++)
// if (h[i][i+l-1] == h[r][r+l-1])
// ans++;
// cout<<l<<" "<<i<<" "<<j<<" "<<ans<<"\n";
// }
for (int l=1; l<=n/2; l++)
for (int i=0; i+l-1<n; i++)
{
ps[0] = (h[i][i+l-1] == h[0][l-1]);
for (int j=1; j+l-1<n; j++)
ps[j] = (h[i][i+l-1] == h[j][j+l-1]) + ps[j-1];
int S = ps[n-l];
for (int j : qp[l][i])
ans += ps[j];
ans += ll(S)*q[l][i].size();
for (int j : q[l][i])
{
// if (j+l-1>=n)
// exit(1);
if (j > 0)
ans -= ps[j-1];
}
}
cout<<ans<<"\n";
}
//aa__
//a_a_
//a__a
//
//aaa+a
//_aa_
//_a_a
//
//__aa
//
//aa+aa
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5840kb
input:
aaaa
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 2ms
memory: 5620kb
input:
axabxbcxcdxd
output:
22
result:
ok single line: '22'
Test #3:
score: 0
Accepted
time: 83ms
memory: 42496kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
536006700
result:
ok single line: '536006700'
Test #4:
score: 0
Accepted
time: 56ms
memory: 29408kb
input:
abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...
output:
136016600
result:
ok single line: '136016600'
Test #5:
score: 0
Accepted
time: 2ms
memory: 5672kb
input:
a
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 2ms
memory: 5648kb
input:
ab
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 2ms
memory: 5672kb
input:
aa
output:
1
result:
ok single line: '1'
Test #8:
score: -100
Wrong Answer
time: 24ms
memory: 15072kb
input:
bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...
output:
210767
result:
wrong answer 1st lines differ - expected: '209015', found: '210767'