QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#558935#8668. 回文路径randomizationCompile Error//C++142.3kb2024-09-11 19:23:012024-09-11 19:23:01

Judging History

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

  • [2024-09-11 19:23:01]
  • 评测
  • [2024-09-11 19:23:01]
  • 提交

answer

#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI"<<endl;}
const int N=2e5+5, B=997, mod=1e9+9;
string s, t; 
int n, ans;
char u[N], v[N]; 
struct hash{
	string s;
	int has[N], po[N], rhas[N];
	void init(string s){
		memset(has,0,sizeof has);
		memset(rhas,0,sizeof rhas); 
		po[0]=1;
		int n=s.size()-1;
		for(int i=1; i<=n; i++)po[i]=po[i-1]*B%mod;
		for(int i=1; i<=n; i++){
			has[i]=(has[i-1]+s[i])*B%mod;
//			cout<<has[i]<<' ';
		}
//		cout<<'\n';
		for(int i=n; i; i--){
			rhas[i]=(rhas[i+1]+s[i])*B%mod;
//			cout<<rhas[i]<<' ';
		}
//		cout<<'\n';
	}
	int ha(int l, int r){
		return (has[r]-has[l-1]*po[r-l+1]%mod+mod)%mod;
	}
	int rha(int l, int r){
		return (rhas[l]-rhas[r+1]*po[r-l+1]%mod+mod)%mod;
	}
}S, T;
void solve(int i, int j){
	int l=0, r=min(i-1,n-j);
	while(l<r){
		int mid=(l+r+1)>>1;
		if(S.ha(i-mid,i)==S.rha(j,j+mid))l=mid;
		else r=mid-1;
	}
	int L=i-l-1, R=j+l;
	if(L&&s[L]==t[R]){
		l=0, r=min(L-1,n-R);
		while(l<r){
			int mid=(l+r+1)>>1;
			if(S.ha(L-mid,L)==T.rha(R,R+mid))l=mid;
			else r=mid-1; 
		}
		L-=l;R+=l;
		ans=max(ans,R-L+2);
	}
	else ans=max(ans,2*l+1+(i!=j));
}
void solvet(int i, int j){
	int l=0, r=min(i-1,n-j);
	while(l<r){
		int mid=(l+r+1)>>1;
		if(T.ha(i-mid,i)==T.rha(j,j+mid))l=mid;
		else r=mid-1;
	}
	int L=i-l, R=j+l+1;
	if(R<=n&&s[L]==t[R]){
		l=0, r=min(L-1,n-R);
		while(l<r){
			int mid=(l+r+1)>>1;
			if(S.ha(L-mid,L)==T.rha(R,R+mid))l=mid;
			else r=mid-1; 
		}
		L-=l;R+=l;
		ans=max(ans,R-L+2);
	}
	else ans=max(ans,2*l+1+(i!=j));
} 
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	cin>>s>>t;
	s=' '+s;t=' '+t;
	S.init(s);T.init(t);
//	cout<<1<<endl;
	for(int i=1; i<=n; i++){
		ans=max(ans,solve(i,i));
	}
//	cout<<1<<endl;
	for(int i=1; i<n; i++)if(s[i]==s[i+1])ans=max(ans,solve(i,i+1));
//	cout<<1<<endl;
//	cout<<ans<<endl;
	for(int i=1; i<=n; i++)ans=max(ans,solvet(i,i));
//	cout<<1<<endl;
	for(int i=1; i<n; i++)if(t[i]==t[i+1])ans=max(ans,solvet(i,i+1));
//	cout<<1<<endl;
//	return 0;
	for(int i=1; i<=n; i++)if(s[i]==t[i]){
		int l=0, r=min(i-1,n-i);
		while(l<r){
			int mid=(l+r+1)>>1;
			if(S.ha(i-mid,i)==T.rha(i,i+mid))l=mid;
			else r=mid-1;
		}
		ans=max(ans,l*2+2);
	}
	cout<<ans<<'\n';
	return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:87:34: error: invalid use of void expression
   87 |                 ans=max(ans,solve(i,i));
      |                             ~~~~~^~~~~
answer.code:90:64: error: invalid use of void expression
   90 |         for(int i=1; i<n; i++)if(s[i]==s[i+1])ans=max(ans,solve(i,i+1));
      |                                                           ~~~~~^~~~~~~
answer.code:93:50: error: invalid use of void expression
   93 |         for(int i=1; i<=n; i++)ans=max(ans,solvet(i,i));
      |                                            ~~~~~~^~~~~
answer.code:95:65: error: invalid use of void expression
   95 |         for(int i=1; i<n; i++)if(t[i]==t[i+1])ans=max(ans,solvet(i,i+1));
      |                                                           ~~~~~~^~~~~~~