QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#453694 | #8701. Border | 2745518585 | 0 | 3ms | 24076kb | C++20 | 3.6kb | 2024-06-24 09:14:48 | 2024-06-24 09:14:49 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1000001;
int n,sa[N],rk[N],he[N],f[N],g[N];
char a[N],b[N];
namespace SA
{
int h[N],x1[N],x2[N];
void init(char a[])
{
int n=strlen(a+1),m=128;
for(int i=1;i<=n;++i)
{
++h[a[i]];
x1[i]=a[i];
}
for(int i=1;i<=m;++i) h[i]+=h[i-1];
for(int i=n;i>=1;--i) sa[h[x1[i]]--]=i;
for(int r=1;r<=n;r<<=1)
{
int p=0;
for(int i=n-r+1;i<=n;++i) x2[++p]=i;
for(int i=1;i<=n;++i) if(sa[i]>r) x2[++p]=sa[i]-r;
for(int i=1;i<=m;++i) h[i]=0;
for(int i=1;i<=n;++i) ++h[x1[i]];
for(int i=1;i<=m;++i) h[i]+=h[i-1];
for(int i=n;i>=1;--i) sa[h[x1[x2[i]]]--]=x2[i],x2[i]=0;
swap(x1,x2);
p=0;
x1[sa[1]]=++p;
for(int i=2;i<=n;++i)
{
if(x2[sa[i]]==x2[sa[i-1]]&&x2[sa[i]+r]==x2[sa[i-1]+r]) x1[sa[i]]=p;
else x1[sa[i]]=++p;
}
if(p==n) break;
m=p;
}
for(int i=1;i<=n;++i) rk[sa[i]]=i;
int p=0;
for(int i=1;i<=n;++i)
{
if(rk[i]==1) continue;
if(p>=1) --p;
int j=sa[rk[i]-1];
while(i+p<=n&&j+p<=n&&a[i+p]==a[j+p]) ++p;
he[rk[i]]=p;
}
}
}
namespace ST
{
int b[N][31],lg[N];
void init()
{
for(int i=1;i<=n;++i) b[i][0]=he[i];
for(int i=1;i<=21;++i)
{
for(int j=(1<<i);j<=min((1<<(i+1))-1,n);++j) lg[j]=i;
}
for(int i=1;i<=21;++i)
{
for(int j=1;j<=n;++j)
{
if(j+(1<<i)-1<=n) b[j][i]=min(b[j][i-1],b[j+(1<<(i-1))][i-1]);
}
}
}
int sum(int x,int y)
{
x=rk[x],y=rk[y];
if(x>y) swap(x,y);
++x;
return min(b[x][lg[y-x]],b[y-(1<<lg[y-x])+1][lg[y-x]]);
}
}
bool check(int x,int y,int t)
{
if(x>y) swap(x,y);
if(y<=t)
{
if(ST::sum(x,y)<t-y) return false;
if(a[t-y+x]!=b[t]) return false;
if(t-x+y<=n)
{
if(ST::sum(t-y+x+1,t+1)<y-x-1) return false;
if(b[t]!=a[t-x+y]) return false;
if(ST::sum(t+1,t-x+y+1)<n-t+x-y) return false;
}
else
{
if(ST::sum(t-y+x+1,t+1)<n-t) return false;
}
}
else if(x<=t)
{
if(t-x+y<=n)
{
if(ST::sum(x,y)<t-x) return false;
if(b[t]!=a[t-x+y]) return false;
if(ST::sum(t+1,t-x+y+1)<n-t+x-y) return false;
}
else
{
if(ST::sum(x,y)<n-y+1) return false;
}
}
else
{
if(ST::sum(x,y)<n-y+1) return false;
}
return true;
}
int main()
{
scanf("%s%s",a+1,b+1);
n=strlen(a+1);
SA::init(a);
ST::init();
for(int i=1;i<=n-1;++i)
{
int p=ST::sum(1,n-i+1)+1;
printf("%d %d\n",i,p);
if(p==i+1)
{
g[i]=max(g[i],i);
continue;
}
if(check(1,n-i+1,p)) f[p]=max(f[p],i);
if(check(1,n-i+1,n-i+p)) f[n-i+p]=max(f[n-i+p],i);
}
// for(int i=1;i<=n;++i) printf("%d ",f[i]);printf("\n");
// for(int i=1;i<=n;++i) printf("%d ",g[i]);printf("\n");
for(int i=1;i<=n;++i) g[i]=max(g[i],g[i-1]);
for(int i=1;i<=n;++i)
{
printf("%d\n",max(f[i],g[min(i-1,n-i)]));
}
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: 3ms
memory: 24076kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
1 1 2 1 3 1 4 1 5 1 6 7 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 18 18 1 19 1 20 1 21 1 22 1 23 7 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 18 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 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 ...
result:
wrong answer 1st numbers differ - expected: '0', 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%