QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620719 | #7780. Dark LaTeX vs. Light LaTeX | Zhou_JK | WA | 1ms | 12032kb | C++23 | 1.7kb | 2024-10-07 20:46:16 | 2024-10-07 20:46:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5005;
int lcp[N][N],lcpr[N][N];
int cnt[N][N];
long long calc(string s,string t)
{
int n=s.size(),m=t.size();
s=" "+s;
t=" "+t;
long long sum=0;
for(int i=0;i<=max(n,m)+1;i++)
for(int j=0;j<=max(n,m)+1;j++)
lcp[i][j]=lcpr[i][j]=cnt[i][j]=0;
for(int i=n;i>=1;i--)
for(int j=n;j>=1;j--)
if(s[i]==s[j]) lcp[i][j]=lcp[i+1][j+1]+1;
else lcp[i][j]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(s[i]==t[j]) lcpr[i][j]=lcpr[i-1][j-1]+1;
else lcpr[i][j]=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cnt[i][lcpr[i][j]]++;
for(int j=max(n,m);j>=1;j--)
cnt[i][j]+=cnt[i][j+1];
}
for(int i=1;i<=n;i++)
for(int j=i+2;j<=n;j++)
if(s[i]==s[j])
{
int mxa=lcp[i][j],mnb=max(j-i-mxa,1);
sum+=cnt[j-1][mnb];
}
return sum;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
string s,t;
cin>>s;
cin>>t;
long long ans=0;
ans+=calc(s,t);
string ss=s,tt=t;
reverse(ss.begin(),ss.end());
reverse(tt.begin(),tt.end());
ans+=calc(tt,ss);
int n=s.size(),m=t.size();
s=" "+s;
t=" "+t;
for(int i=0;i<=max(n,m)+1;i++)
for(int j=0;j<=max(n,m)+1;j++)
lcpr[i][j]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(s[i]==t[j]) lcpr[i][j]=lcpr[i-1][j-1]+1;
else lcpr[i][j]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ans+=lcpr[i][j];
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7996kb
input:
abab ab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9740kb
input:
abab abaaab
output:
29
result:
ok 1 number(s): "29"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7968kb
input:
abcd abcde
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7668kb
input:
aaba ba
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 12032kb
input:
babababaaabbaabababbbaabbbababbaaaaa aaaabbaababbab
output:
1025
result:
wrong answer 1st numbers differ - expected: '1161', found: '1025'