QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557425#8668. 回文路径h_rains0 9ms7832kbC++143.4kb2024-09-11 09:41:202024-09-11 09:41:22

Judging History

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

  • [2024-09-11 09:41:22]
  • 评测
  • 测评结果:0
  • 用时:9ms
  • 内存:7832kb
  • [2024-09-11 09:41:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int unsigned long long

const int maxn=1e5+5;
const int base=233;

int pw[maxn];
int h1[maxn],h2[maxn],h3[maxn],h4[maxn];

int solve1(int l,int r)
{
	return h1[r]-h1[l-1]*pw[r-l+1];
}

int solve2(int l,int r)
{
	return h2[l]-h2[r+1]*pw[r-l+1];
}

int solve3(int l,int r)
{
	return h3[r]-h3[l-1]*pw[r-l+1];
}

int solve4(int l,int r)
{
	return h4[l]-h4[r+1]*pw[r-l+1];
}

signed main()
{
	int n,ans=0;
	cin>>n;
	string s,s2;
	cin>>s>>s2;pw[0]=1;
	for(int i=1;i<=n;i++) pw[i]=pw[i-1]*base;
	for(int i=1;i<=n;i++) h1[i]=h1[i-1]*base+(s[i-1]-'a');
	for(int i=n;i>=1;i--) h2[i]=h2[i+1]*base+(s[i-1]-'a');
	for(int i=1;i<=n;i++) h3[i]=h3[i-1]*base+(s2[i-1]-'a');
	for(int i=n;i>=1;i--) h4[i]=h4[i+1]*base+(s2[i-1]-'a');
	if(s[0]==s2[n-1]&&solve1(2,n)==solve2(2,n))
	{
		cout<<n+1<<endl;
		return 0;
	}
	if(s2[0]==s[n-1]&&solve3(2,n)==solve4(2,n))
	{
		cout<<n+1<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		int l=1,r=min(i-1,n-i);
		while(l<=r)
		{
			int mid=l+r>>1;
			if(solve1(i-mid,i-1)==solve2(i+1,i+mid)) l=mid+1;
			else r=mid-1;
		}
		int pos1=i-l+1,pos2=i+l-1;
//		l=1,r=min(pos1-1,n-pos2+1);
//		while(l<=r)
//		{
//			int mid=l+r>>1;
//			if(solve1(pos1-mid,pos1-1)==solve4(pos2,pos2+mid-1)) l=mid+1;
//			else r=mid-1;
//		}
//		if(pos1==pos2&&s[pos1-1]==s2[pos1-1])
//		{
//			int L=1,R=min(pos1-1,n-pos2);
//			while(L<=R)
//			{
//				int mid=L+R>>1;
//				if(solve1(pos1-mid,pos1-1)==solve4(pos2+1,pos2+mid)) L=mid+1;
//				else R=mid-1;
//			}
//			ans=max(ans,2*L);
//		}
//		pos1=pos1-l+1,pos2=pos2+l-1;
		ans=max(ans,pos2-pos1+1);
//		if(i!=n&&s[i]==s[i+1])
//		{
//			l=1,r=min(i-1,n-i-1);
//			while(l<=r)
//			{
//				int mid=l+r>>1;
//				if(solve1(i-mid,i-1)==solve2(i+2,i+mid)) l=mid+1;
//				else r=mid-1;
//			}
//			pos1=i-l+1,pos2=i+l;
//			l=1,r=min(pos1-1,n-pos2+1);
//			while(l<=r)
//			{
//				int mid=l+r>>1;
//				if(solve1(pos1-mid,pos1-1)==solve4(pos2,pos2+mid-1)) l=mid+1;
//				else r=mid-1;
//			}
//			pos1=pos1-l+1,pos2=pos2+l-1;
//			ans=max(ans,pos2-pos1+1);
//		}
	}
	swap(h1,h2);
	swap(h3,h4);
	swap(h1,h3);
	swap(h2,h4);
	for(int i=1;i<=n;i++)
	{
		int l=1,r=min(i-1,n-i);
		while(l<=r)
		{
			int mid=l+r>>1;
			if(solve1(i-mid,i-1)==solve2(i+1,i+mid)) l=mid+1;
			else r=mid-1;
		}
		int pos1=i-l+1,pos2=i+l-1;
//		l=1,r=min(pos1-1,n-pos2+1);
//		while(l<=r)
//		{
//			int mid=l+r>>1;
//			if(solve1(pos1-mid,pos1-1)==solve4(pos2,pos2+mid-1)) l=mid+1;
//			else r=mid-1;
//		}
//		if(pos1==pos2&&s[pos1-1]==s2[pos1-1])
//		{
//			int L=1,R=min(pos1-1,n-pos2);
//			while(L<=R)
//			{
//				int mid=L+R>>1;
//				if(solve1(pos1-mid,pos1-1)==solve4(pos2+1,pos2+mid)) L=mid+1;
//				else R=mid-1;
//			}
//			ans=max(ans,2*L);
//		}
//		pos1=pos1-l+1,pos2=pos2+l-1;
		ans=max(ans,pos2-pos1+1);
//		if(i!=n&&s[i]==s[i+1])
//		{
//			l=1,r=min(i-1,n-i-1);
//			while(l<=r)
//			{
//				int mid=l+r>>1;
//				if(solve1(i-mid,i-1)==solve2(i+2,i+mid)) l=mid+1;
//				else r=mid-1;
//			}
//			pos1=i-l+1,pos2=i+l;
//			l=1,r=min(pos1-1,n-pos2+1);
//			while(l<=r)
//			{
//				int mid=l+r>>1;
//				if(solve1(pos1-mid,pos1-1)==solve4(pos2,pos2+mid-1)) l=mid+1;
//				else r=mid-1;
//			}
//			pos1=pos1-l+1,pos2=pos2+l-1;
//			ans=max(ans,pos2-pos1+1);
//		}
	}
	cout<<ans<<endl; 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7516kb

input:

1000
mfmlkrasfiudkzrjzyrlbpitvzfrlmjdzsurtdcmnqpsyfgobbstvplqylvciloomaljyssxtrrccywyirfvlcnchwkfwbdaoxzpfpvlruptganojnfxmnlqetptmlmoyluxvaipghtlaszoozscdmjomobyzboqqmvqjpbfjsoczhkwrlcauzjceqikbaeuiqahnldpqmohfjfzgkbfdbqnoxispkejvpncwsyelebqumapgbfdrjvuaxaphnkciwzkruijmanwslkwosgyfhwbnsthhtxrhrzlgtt...

output:

3

result:

wrong answer 1st lines differ - expected: '6', found: '3'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 20
Accepted
time: 8ms
memory: 7640kb

input:

100000
ibhqhodaqcwqggmckoemulhkgbfidceskhefhsonccepfodalabaqgobpgcnaervbccadkbtsdigsoqochklocgbjjqcdhwrlacamprsoilyhiwkkjalicedhbxajrkhjgivjhnfdibkdwtexnnriegejazmohlfijbeigfmpngncokxhifjfuwuogccdfglfbxobnarmgfhgpnjjewicgfhcmfbbnjbbjjtbprnagpchcihcihfhcikeaecefdgeegtzlfdolhfieahiehdfcaflmndmcojceblf...

output:

9

result:

ok single line: '9'

Test #12:

score: 0
Wrong Answer
time: 9ms
memory: 7832kb

input:

100000
fruiifpdggdnsbgamakpjipicaidfdjpffioqcwioaafbpdagmbbakqpekjabcljockpvcifilcjakhcboolgjbnmmrbeawcjopbccjgncdaucighprheiaqofriccfdbydbhijeelbthsmqbhcddlfemqkvdbflkdrifckarqwlaafifmqibssfukblchalkzdefnccaiabrhcrmisdeiqddccrqhiiwcqqakbfhebkiecahgdlibhgmegkfbuibcarcbajpdeboigeoctdljmqeckdfqahiecla...

output:

7

result:

wrong answer 1st lines differ - expected: '9', found: '7'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%