QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#848806#8701. Bordertongzhenxuan#23 3ms14280kbC++142.5kb2025-01-09 09:50:552025-01-09 09:50:56

Judging History

你现在查看的是最新测评结果

  • [2025-01-09 09:50:56]
  • 评测
  • 测评结果:23
  • 用时:3ms
  • 内存:14280kb
  • [2025-01-09 09:50:55]
  • 提交

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-pw[r1-op]*(a[op]-'a'+1)%mod+pw[r1-op]*(b[op]-'a'+1)%mod+mod)%mod;
    }
    if(op!=0 && l2<=op && op<=r2) {
        h2=(h2-pw[r2-op]*(a[op]-'a'+1)%mod+pw[r2-op]*(b[op]-'a'+1)%mod+mod)%mod;
    }
    return h1==h2;
}
int main(){
    // freopen("data.in","r",stdin);
    // freopen("data.out","w",stdout);
    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+tmp;
            else tmp=p+tmp;
            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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 23
Accepted

Test #1:

score: 23
Accepted
time: 0ms
memory: 12124kb

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: 12064kb

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: 12108kb

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: 23
Accepted
time: 1ms
memory: 11976kb

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: 23
Accepted
time: 1ms
memory: 12100kb

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: 23
Accepted
time: 0ms
memory: 12128kb

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: 3ms
memory: 14176kb

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
Accepted
time: 2ms
memory: 14140kb

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:

ok 3182 numbers

Test #9:

score: 31
Accepted
time: 2ms
memory: 14280kb

input:

fbcababaabaababaababdababaabaababaababcababaababcababaabaababaababcababaababcababaabaababaababcababaababcababaabaababaababcababaabaababaababcababaababcababaabaababaababcababaababcababaabaababaababdababaabaababaababcababaababcababaabaababaababcababaababcababaabaababaababcababaababcababaabaabebaababda...

output:

103
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:

ok 4057 numbers

Test #10:

score: 0
Wrong Answer
time: 2ms
memory: 14256kb

input:

accaeaabacabaabacabacabaabacabaabacdbacabaabacabaabacabacabaabacabaabacdbacabaabacabaabacabacabaabacabacabaabacabaabacabacabaabacabaabacdbacabaabacabaabacabacabaabacabacabaabacabaabacabacabaabacabaabacdbacabaabacabaabacabacabaabacabacabaabacabaabacabacabaabacabaabacdbacabaabacabaabacabacabaabacabaab...

output:

0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 714th numbers differ - expected: '630', found: '713'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%