QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#748661 | #7780. Dark LaTeX vs. Light LaTeX | monui | WA | 24ms | 200156kb | C++23 | 1.9kb | 2024-11-14 21:00:40 | 2024-11-14 21:00:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define lowbit(x) x&(-x)
const int N=5010;
const int M=998244353;
string a,b;
unordered_map<int,int> st_a,st_b;
int na,nb;
int hash_a[N],hash_b[N];
int fac[N];
void init_init(){
fac[0]=1;
for(int i=1;i<N;i++){
fac[i]=(fac[i-1]*31)%M;
}
}
void init(string& s,int len,int* ans){
for(int i=1;i<=len;i++){
ans[i]=ans[i-1]*31+s[i]-'a'+13;
ans[i]%=M;
}
}
void calc(string& s,int len,unordered_map<int,int>& st,int* ans,int d){
vector<vector<int>> op(N,vector<int>(N,0));
vector<int> lst(N,0);
for(int i=1;i<=len;i++){
for(int j=len;j>i;j--){
lst[j]=0;
if(s[i]!=s[j]) continue;
if(s[i-1]==s[j-1]) lst[j]=lst[j-1]+1;
op[i+1][j]-=1;
op[i+1][min(j-lst[j]-1,i+1)]+=1;
}
}
for(int i=1;i<=len;i++){
int res=0;
for(int j=i;j<=len;j++){
res+=op[i][j];
int num=res+d;
if(num<=0) continue;
int to=ans[j]-ans[i-1]*fac[j-i+1]%M;
to=(to%M+M)%M;
st[to]+=num;
}
}
}
int getans(string& s,int len,unordered_map<int,int>& st,int* ans){
int res=0;
for(int i=1;i<=len;i++){
for(int j=i;j<=len;j++){
int to=ans[j]-ans[i-1]*fac[j-i+1]%M;
to=(to%M+M)%M;
res+=st[to];
}
}
return res;
}
void solve(){
cin>>a>>b;
na=a.size(),nb=b.size();
a="#"+a;b="#"+b;
init_init();
init(a,na,hash_a);
init(b,nb,hash_b);
calc(a,na,st_a,hash_a,1);
calc(b,nb,st_b,hash_b,0);
int res=getans(a,na,st_b,hash_a)+getans(b,nb,st_a,hash_b);
cout<<res<<endl;
}
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);
int t=1;
// cin>>t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 24ms
memory: 200156kb
input:
abab ab
output:
6
result:
wrong answer 1st numbers differ - expected: '8', found: '6'