QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#851383#8701. BorderANIG23 12ms57000kbC++141.7kb2025-01-10 18:27:352025-01-10 18:27:35

Judging History

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

  • [2025-01-10 18:27:35]
  • 评测
  • 测评结果:23
  • 用时:12ms
  • 内存:57000kb
  • [2025-01-10 18:27:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int N=2e6+5;
string s,t;
int n,p1[N],p2[N],f1[N],f2[N];
set<int>jl;
vector<int>g[N];
ull h[N],pw[N];
ull gets(int l,int r){
	return h[r]-h[l-1]*pw[r-l+1];
}
ull gets(int l,int r,int k,int b){
	if(k<l||k>r)return gets(l,r);
	return gets(l,k-1)*pw[r-k+1]+b*pw[r-k]+gets(k+1,r);
}
signed main(){
	cin>>s>>t;
	jl.insert(0);
	n=s.size();
	for(int i=1;i<=n;i++)p1[i]=s[i-1]-'a'+1,p2[i]=t[i-1]-'a'+1;
	pw[0]=1;
	for(int i=1;i<=n;i++)h[i]=h[i-1]*131+p1[i],pw[i]=pw[i-1]*131;
	f1[1]=n;
	while(p1[f1[2]+1]==p1[f1[2]+2])f1[2]++;
	for(int i=3,k=2;i<=n;i++){
		int to=i-k+1;
		if(i+f1[to]<k+f1[k])f1[i]=f1[to];
		else{
			f1[i]=max(0,k+f1[k]-i);
			while(p1[f1[i]+1]==p1[i+f1[i]])f1[i]++;
			k=i;
		}
	}
	reverse(p1+1,p1+n+1);
	f2[1]=n;
	while(p1[f2[2]+1]==p1[f2[2]+2])f2[2]++;
	for(int i=3,k=2;i<=n;i++){
		int to=i-k+1;
		if(i+f2[to]<k+f2[k])f2[i]=f2[to];
		else{
			f2[i]=max(0,k+f2[k]-i);
			while(p1[f2[i]+1]==p1[i+f2[i]])f2[i]++;
			k=i;
		}
	}
	reverse(p1+1,p1+n+1);
	reverse(f2+1,f2+n+1);
	for(int i=1;i<=n;i++){
		if(f1[n-i+1]==i)jl.insert(i);
		else{
			if(2*i<=n){
				if(f1[n-i+1]+f2[i]+1==i){
					g[f1[n-i+1]+1].push_back(i);
					g[n-f2[i]].push_back(i);
				}
			}else{
				if(gets(f1[n-i+1]+2,i-f2[i]-1)==gets(n-i+f1[n-i+1]+2,n-f2[i]-1)){
					g[n-i+f1[n-i+1]+1].push_back(i);
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(p1[i]==p2[i]){
			cout<<(*prev(jl.end()))<<"\n";
		}else{
			int res=*prev(jl.lower_bound(min(i,n-i+1)));
			for(auto c:g[i]){
				if(gets(1,c,i,p2[i])==gets(n-c+1,n,i,p2[i]))res=max(res,c);
			}
			cout<<res<<"\n";
		}
	}
}

詳細信息

Subtask #1:

score: 23
Accepted

Test #1:

score: 23
Accepted
time: 3ms
memory: 57000kb

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: 4ms
memory: 56928kb

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: 4ms
memory: 56988kb

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: 8ms
memory: 56852kb

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: 4ms
memory: 56988kb

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

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: 12ms
memory: 54980kb

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: '4623'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%