QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#532730#8701. BorderdengrkCompile Error//C++141.8kb2024-08-25 10:36:232024-08-25 10:36:24

Judging History

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

  • [2024-08-25 10:36:24]
  • 评测
  • [2024-08-25 10:36:23]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <random>
#define ULL unsigned long long
using namespace std;
const int N=(int)2e6+3;
mt19937_64 myrand(time(0));
char a[N],b[N];
int n,z[N],y[N],ans[N];
ULL Hmul,Hpow[N],Hval[N];
void init_Hash(){
	do
		Hmul=myrand();
	while(Hmul<30);
	Hpow[0]=1,Hval[0]=0;
	for(int i=1;i<=n;i++)
		Hpow[i]=Hpow[i-1]*Hmul;
	for(int i=1;i<=n;i++)
		Hval[i]=Hval[i-1]*Hmul+(a[i-1]-'a')+1;
}
ULL Hash(int l,int r){
	if(l>r) return 0;
	return Hval[r+1]-Hval[l]*Hpow[r-l+1];
}
int main(){
//	freopen("border.in","r",stdin);
//	freopen("border.out","w",stdout);
	int i,j,l,r,s1;
	gets(a),gets(b);
	n=strlen(a);
	l=r=-1,z[0]=n;
	for(i=1;i<n;i++){
		z[i]=max(min(z[i-l],r-i),0);
		while(i+z[i]<n&&a[i+z[i]]==a[z[i]]) z[i]++;
		if(i+z[i]>r) l=i,r=i+z[i];
	}
	l=r=n+1,y[n-1]=n;
	for(i=n-2;i>=0;i--){
		y[i]=max(min(y[i-r+n-1],i-l),0);
		while(i>=y[i]&&a[i-y[i]]==a[n-1-y[i]]) y[i]--;
		if(i-y[i]<l) l=i-y[i],r=i;
	}
	for(s1=1;s1<n;s1++)
		if(s1+z[s1]==n) break;
	for(i=0;i<n;i++)
		if(a[i]==b[i]) ans[i]=n-s1;
	for(i=n-1,s1=j=0;i>=j;i--,j++){
		ans[i]=max(ans[i],s1);
		ans[j]=max(ans[j],s1);
		if(i+z[i]==n) s1=n-i;
	}
	init_Hash();
	for(i=1;i<n;i++){
		if(i+z[i]==n) continue;
		if(z[i]<i&&b[z[i]]==a[i+z[i]])
			if(n-1-i-y[n-1-i]==z[i])
				ans[z[i]]=max(ans[z[i]],n-i);
		if(i+z[i]<n-i){
			if(n-1-i-y[n-1-i]>i+z[i]) continue;
			if(a[i*2+z[i]]!=a[z[i]]) continue;
			if(b[i+z[i]]!=a[z[i]]) continue;
			if(Hash(z[i]+1,i+z[i]-1)==Hash(i+z[i]+1,i*2+z[i]-1))
				ans[i+z[i]]=max(ans[i+z[i]],n-i);
		}
		else
			if(b[i+z[i]]==a[z[i]])
				if(n-1-y[n-1-i]==i+z[i])
					ans[i+z[i]]=max(ans[i+z[i]],n-i);
	}
	for(i=0;i<n;i++)
		printf("%d\n",ans[i]);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:31:9: error: ‘gets’ was not declared in this scope; did you mean ‘getw’?
   31 |         gets(a),gets(b);
      |         ^~~~
      |         getw