QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#834288#8701. Borderppllxx_9G0 2ms12140kbC++141.7kb2024-12-27 14:46:382024-12-27 14:46:38

Judging History

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

  • [2024-12-27 14:46:38]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:12140kb
  • [2024-12-27 14:46:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ULL unsigned long long
const int N = 2e6+5,B = 233;
int n,pi[N],ans[N];
char s[N],t[N];
ULL hs[N],p[N];
vector<int> v;
inline ULL get(int l,int r,int k=0)
{
	if(k>r||k<l) return hs[r]-hs[l-1]*p[r-l+1];
	else
	{
		ULL res=0;
		if(k>l) res+=hs[k-1]-hs[l-1]*p[k-l],res*=p[r-k+1];
		if(k<r) res+=hs[r]-hs[k]*p[r-k];
		res+=t[k]*p[r-k];
		return res;
	}
}

int main()
{
	// freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
	scanf("%s%s",s+1,t+1); n=strlen(s+1);
	p[0]=1; for(int i=1;i<=n;i++) p[i]=p[i-1]*B;
	for(int i=1;i<=n;i++) hs[i]=hs[i-1]*B+s[i];
	for(int i=2,j=0;i<=n;i++)
	{
		while(j&&s[i]!=s[j+1]) j=pi[j];
		pi[i]=(j+=s[i]==s[j+1]);
	}
	int x=pi[n];
	while(x) {if(x<=(n>>1)) v.push_back(x); x=pi[x];}
	for(int len=1;len<n;len++)
	{
		if(get(1,len)==get(n-len+1,n)) continue;
		int l=1,r=len,pos=len+1;
		while(l<=r)
		{
			int mid=l+r>>1;
			if(get(1,mid)!=get(n-len+1,n-len+mid)) r=mid-1,pos=mid;
			else l=mid+1;
		}
		// printf("%d$$\n",pos);
		if(get(1,len,pos)==get(n-len+1,n)) ans[pos]=len;
		if(get(1,len)==get(n-len+1,n,n-len+pos)) ans[n-len+pos]=len;
	}
	sort(v.begin(),v.end());
	// for(int i:v) printf("%d ",i); putchar('\n');
	for(int i=1;i<=n;i++)
	{
		if(s[i]==t[i]) {printf("%d\n",pi[n]); continue;}
		auto pos=lower_bound(v.begin(),v.end(),min(i,n-i+1));
		if(pos==v.begin())
		{
			printf("%d\n",ans[i]);
		}
		else
		{
			pos--;
			// printf("%d %d$$\n",i,*pos);
			printf("%d\n",max(ans[i],*pos));
		}
		// if(s[i]==t[i]) printf("%d\n",pi[n]);
		// else printf("%d\n",max(ans[i],(get)));
	}
	// for(int i=1;i<=n;i++) printf("%d ",pi[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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

input:

cbaababaabacbaabadbaababaabacbaabacbaaba
aabwaxjbbabtalbabcasbabibbabaabbabaabiac

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
0
0
1

result:

wrong answer 18th numbers differ - expected: '23', found: '6'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%