QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#848784 | #8701. Border | tongzhenxuan# | 0 | 0ms | 12096kb | C++14 | 2.5kb | 2025-01-09 09:38:50 | 2025-01-09 09:38:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define maxn 2000005
#define ll long long
char a[maxn],b[maxn];
int nxt[maxn],res[maxn],ans[maxn],vis[maxn],n;
const ll mod=998244353,bas=31;
ll hsh[maxn],pw[maxn];
int ck(int l1,int r1,int l2,int r2,int op){
long long h1=(hsh[r1]-hsh[l1-1]*pw[r1-l1+1]%mod+mod)%mod;
long long h2=(hsh[r2]-hsh[l2-1]*pw[r2-l2+1]%mod+mod)%mod;
if(op!=0 && l1<=op && op<=r1) {
h1=(h1-(a[op]-'a'+1)*pw[r1-op]%mod+(b[op]-'a'+1)*pw[r1-op]%mod+mod)%mod;
}
if(op!=0 && l2<=op && op<=r2) {
h2=(h2-(a[op]-'a'+1)*pw[r2-op]%mod+(b[op]-'a'+1)*pw[r2-op]%mod+mod)%mod;
}
return h1==h2;
}
int main(){
// freopen("data.in","r",stdin);
scanf("%s",a+1);
scanf("%s",b+1);
n=strlen(a+1);
int j=0;
pw[0]=1;
for(int i=1;i<=n;i++) pw[i]=pw[i-1]*bas%mod;
for(int i=1;i<=n;i++) hsh[i]=(hsh[i-1]*bas+(a[i]-'a'+1))%mod;
for(int i=2;i<=n;i++){
while(j && a[i]!=a[j+1]) j=nxt[j];
j+=(a[i]==a[j+1]);
nxt[i]=j;
}
for(int i=1;i<=n;i++)if(a[i]==b[i])ans[i]=nxt[n];
for(int len=n/2;len>=1;len--)
if(!ck(1,len,n-len+1,n,0)){
int l=1,r=len,mid,tmp=0,p=n-len;
while(l<=r){
mid=(l+r)>>1;
if(!ck(1,mid,p+1,p+mid,0)) tmp=mid,r=mid-1;
else l=mid+1;
}
if(ck(1,len,p+1,p+len,tmp)) ans[tmp]=max(ans[tmp],len);
if(ck(1,len,p+1,p+len,p+tmp)) ans[p+tmp]=max(ans[p+tmp],len);
}
else {
for(int i=len+1;i<=(n+1)/2;i++) if(!res[i]) res[i]=len;else break;
for(int i=n-len;i> (n+1)/2;i--) if(!res[i]) res[i]=len;else break;
}
//repeat
for(int len=n-1;len>n/2;len--){
int t=n-len,tmp=0,cnt=0;
vis[0]=vis[(n-1)/t+1]=1;
for(int i=0;i+t<n;i+=t)
vis[i/t+1]=!ck(i+1,i+t,i+1+t,i+2*t,0);
for(int i=t;i+t<n;i+=t)
cnt+=(vis[i/t]==1 && vis[i/t+1]==1);
if(cnt>1) continue;
for(int i=0;i+t<n;i+=t) if(vis[i/t+1]==1){
int p=i+t,l=1,r=min(t,n-p),mid;
while(l<=r){
mid=(l+r)>>1;
if(!ck(i+1,i+mid,p+1,p+mid,0)) tmp=mid,r=mid-1;
else l=mid+1;
}
if(vis[i/t]) tmp=i+mid;
else tmp=p+mid;
if(ck(1,len,n-len+1,n,tmp)) ans[tmp]=max(ans[tmp],len);
}
}
for(int i=1;i<=n;i++) printf("%d\n",max(res[i],ans[i]));
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 23
Accepted
time: 0ms
memory: 12008kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
0 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 17 17 17 17 17 17 17 17 17 17 17 6 6 6 6 6 6 6 6 6 6 6 0 0 0 3 0 1
result:
ok 45 numbers
Test #2:
score: 23
Accepted
time: 0ms
memory: 12084kb
input:
cbaababaabacbaabadbaababaabacbaabacbaaba aabwaxjbbabtalbabcasbabibbabaabbabaabiac
output:
3 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 23 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 0 0 0 0 0 1
result:
ok 40 numbers
Test #3:
score: 23
Accepted
time: 0ms
memory: 12088kb
input:
cadaabacabacabacabaabacabacadaabacabacaba bbbbbabtbabababalalbawababababbaoababebdc
output:
2 0 4 0 0 0 0 0 0 0 0 0 0 0 0 15 15 15 15 15 15 15 15 15 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 4 1
result:
ok 41 numbers
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 12096kb
input:
dabacbaadcbaadabacbaadabecbaadcbaadabacbaadabacbaa ababaabbyaarbabfbvdbuaoaaaabbaaabbababaabbababqadd
output:
2 0 0 0 0 0 0 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 2 1
result:
wrong answer 25th numbers differ - expected: '29', found: '8'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%