QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#846612 | #8701. Border | masterhuang | 0 | 2ms | 9704kb | C++23 | 1.4kb | 2025-01-07 11:01:11 | 2025-01-07 11:01:19 |
answer
#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=2e6+5,mod=472399997,g=30,_g=110226666;
int n,pw[N],_pw[N],s[N],ans[N],m,b[N];bool v[N];
string A,B;
inline int get(int l,int r){return 1ll*(s[r]-s[l-1]+mod)*_pw[l]%mod;}
inline int get(int l,int r,int w,int d){
if(w<l||w>r) return get(l,r);
return (s[r]-s[l-1]+mod+1ll*pw[w]*(mod+d))%mod*_pw[l]%mod;
}
inline void upd(int x,char c,int v){if(B[x]==c) ans[x]=max(ans[x],v);}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>A>>B;
n=A.size();A=" "+A;B=" "+B;
for(int i=pw[0]=1;i<=n;i++) pw[i]=1ll*pw[i-1]*g%mod;
for(int i=_pw[0]=1;i<=n;i++) _pw[i]=1ll*_pw[i-1]*_g%mod;
for(int i=1;i<=n;i++) s[i]=(s[i-1]+1ll*pw[i]*(A[i]-'a'))%mod;
for(int i=1;i<n;i++) if(get(1,i)==get(n-i+1,n)) v[b[++m]=i]=1;
for(int i=1;i<=n;i++)
{
if(A[i]==B[i]) ans[i]=b[m];
else ans[i]=max(ans[i],(int)(upper_bound(b+1,b+1+m,min(i-1,n-i))-b-1));
}
for(int i=1;i<n;i++) if(!v[i])
{
int j=n-i+1,l=1,r=i,mid,res=0;
while(l<=r)
{
mid=(l+r)>>1;
(get(1,mid)==get(j,j+mid-1))?res=mid,l=mid+1:r=mid-1;
}
int w=res+1,d=A[j+res]-A[res+1];
if(get(1,i,w,d)==get(j,n,w,d)) upd(w,A[j+res],i);
w=j+res,d=-d;
if(get(1,i,w,d)==get(j,n,w,d)) upd(w,A[res+1],i);
}
for(int i=1;i<=n;i++) cout<<ans[i]<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9704kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 0 0 0 3 0 1
result:
wrong answer 7th numbers differ - expected: '6', found: '1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%