QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#453695 | #8701. Border | 2745518585 | 23 | 8ms | 24192kb | C++20 | 3.6kb | 2024-06-24 09:15:24 | 2024-06-24 09:15:26 |
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: 23
Accepted
Test #1:
score: 23
Accepted
time: 8ms
memory: 22080kb
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: 0
Accepted
time: 4ms
memory: 24148kb
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: 0
Accepted
time: 7ms
memory: 22128kb
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
Accepted
time: 4ms
memory: 24140kb
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 29 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:
ok 50 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 22132kb
input:
edacbcacacbcaecbcacacbcadacbcacacbca sabaaabtbaaabaaalblbawaeabaaababoaae
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0 0 0 0 0 1
result:
ok 36 numbers
Test #6:
score: 0
Accepted
time: 3ms
memory: 22092kb
input:
cbaababaabacbaabacbaabdbaabacbaabacbaaba aabbababbaoaabbxbaabbaqabbabltbpagaabcac
output:
3 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 0 0 0 3 0 1
result:
ok 40 numbers
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #7:
score: 31
Accepted
time: 4ms
memory: 24192kb
input:
abacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacababacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacaecabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacababacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacad...
output:
27 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75...
result:
ok 4623 numbers
Test #8:
score: -31
Wrong Answer
time: 6ms
memory: 22112kb
input:
gcdcbcacacacbcacdcbcacaedcbcacacacbcacdcfcacacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacagcdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcaca...
output:
187 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 2931st numbers differ - expected: '508', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%