QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#413253 | #8701. Border | grass8cow | 0 | 0ms | 18192kb | C++17 | 1.7kb | 2024-05-17 10:38:46 | 2024-05-17 10:38:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
char s[2001000],t[2010000];
int z_[2010010],z[2010001];
void doi(){
memset(z,0,sizeof(z));
z[1]=n;
for(int i=2,t=0,mr=0;i<=n;i++){
if(i<=mr)z[i]=min(mr-i+1,z[i-t+1]);
while(i+z[i]<=n&&s[1+z[i]]==s[i+z[i]])z[i]++;
if(i+z[i]-1>mr)t=i,mr=i+z[i]-1;
}
}
const int mod=1e9+7,W=131;
int hs[2001000],wi[2001000],ans[2001000];
void ie(int x,int z){
if(x+z<=n&&t[x]!=s[x+z])return;
if(x-z>=1&&t[x]!=s[x-z])return;
ans[x]=max(ans[x],n-z);
}
int has(int l,int r){
return ((hs[r]-1ll*hs[l-1]*wi[r-l+1]%mod)%mod+mod)%mod;
}
int main(){
scanf("%s%s",s+1,t+1);n=strlen(s+1);
printf("!%d\n",n);
reverse(s+1,s+n+1);doi();
for(int i=1;i<=n;i++)z_[i]=z[i];reverse(s+1,s+n+1);doi();
wi[0]=1;
for(int i=1;i<=n;i++)wi[i]=1ll*wi[i-1]*W%mod,hs[i]=(1ll*W*hs[i-1]%mod+s[i])%mod;
int e_=0;
for(int e=1;e<n;e++){
int z1=z[e+1],z2=z_[e+1];
if(e==17)printf("?%d %d\n",z1,z2);
if(z1+z2>=n-e){
if(n-e+1<=e){
int pl=n-e+1,pr=e;
for(int o=pl;o<=(e_?(n-e_):pr);o++)ans[o]=max(ans[o],n-e);
for(int o=(e_?(e_+1):pl);o<=pr;o++)ans[o]=max(ans[o],n-e);
e_=e;
}
}
else if(z1+z2==n-e-1)ie(z1+1,e),ie(z1+1+e,e);
else{
int p1=z1+1,p2=n-e-z2;
if(p1+e!=p2)continue;
if(has(p1+1,p2-1)!=has(p1+1+e,p2+e-1))continue;
ie(p2,e);
}
}
if(e_){for(int i=1;i<=n;i++)if(s[i]==t[i])ans[i]=max(ans[i],n-e_);}
for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 18192kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
!45 ?0 22 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:
wrong output format Expected integer, but "!45" found
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%