QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#836912#8701. BorderOIer_Automation23 2ms15856kbC++141.4kb2024-12-29 09:54:262024-12-29 09:54:26

Judging History

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

  • [2024-12-29 09:54:26]
  • 评测
  • 测评结果:23
  • 用时:2ms
  • 内存:15856kb
  • [2024-12-29 09:54:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define il inline
#define ull unsigned long long

const int N=2e6+5,Q=37;

int n,len;
int z1[N],z2[N],ans[N];
ull q[N],hsh[N];
char s[N],t[N];

il void Z(int n,char s[]){
	z1[1]=n;
	for(int i=2,l=0,r=0;i<=n;i++){
		if(i<=r)z1[i]=min(z1[i-l+1],r-i+1);
		while(i+z1[i]<=n&&s[i+z1[i]]==s[z1[i]+1])++z1[i];
		if(i+z1[i]-1>r)l=i,r=i+z1[i]-1;
		if(i+z1[i]>n)len=i;
	}
	z2[n]=n;
	for(int i=n-1,l=n+1,r=n+1;i;i--){
		if(i>=l)z2[i]=min(z2[n-r+i],i-l+1);
		while(i-z2[i]>=0&&s[i-z2[i]]==s[n-z2[i]])++z2[i];
		if(i-z2[i]+1<l)l=i-z2[i]+1,r=i;
	}
	return ;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>(s+1)>>(t+1);
	n=strlen(s+1);
	q[0]=1;
	for(int i=1;i<=n;i++)q[i]=q[i-1]*Q;
	for(int i=1;i<=n;i++)hsh[i]=hsh[i-1]*Q+s[i]-'a'+1;
	Z(n,s);
//	if(n>100)cout<<len<<"\n";
	for(int i=1,j=0;i<=n/2;i++)ans[i]=j,z2[i]>=i?j=z2[i]:0;
	for(int i=n,j=0;i>n/2;i--)ans[i]=j,i+z1[i]>n?j=z1[i]:0;
	for(int i=1;i<=n;i++)t[i]==s[i]?ans[i]=len:0;
	for(int i=1;i<n;i++){
		int pre=z1[n-i+1],nxt=z2[i];
		if(pre+nxt==i-1){
			if(pre+1<n-i+1&&t[pre+1]==s[n-nxt])ans[pre+1]=max(ans[pre+1],i);
			if(n-nxt>i&&t[n-nxt]==s[pre+1])ans[n-nxt]=max(ans[n-nxt],i);
		}else if(pre+nxt==i*2-n-1){
			ull h1=hsh[i],h2=hsh[n]-hsh[n-i]*q[i];
			h1+=(t[i-nxt]-s[i-nxt])*q[nxt],h2+=(t[i-nxt]-s[i-nxt])*q[i-pre-1];
			if(h1==h2)ans[i-nxt]=max(ans[i-nxt],i);
		}
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 23
Accepted

Test #1:

score: 23
Accepted
time: 2ms
memory: 13824kb

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

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

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: 2ms
memory: 13888kb

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: 0ms
memory: 13824kb

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: 1ms
memory: 13956kb

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: 0
Wrong Answer
time: 2ms
memory: 15856kb

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:

wrong answer 3139th numbers differ - expected: '717', found: '4622'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%