QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#711825#9522. A Simple String Problemxyz123#AC ✓872ms30420kbC++233.7kb2024-11-05 13:38:382024-11-06 21:49:58

Judging History

你现在查看的是测评时间为 2024-11-06 21:49:58 的历史记录

  • [2024-11-10 22:38:17]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:881ms
  • 内存:31216kb
  • [2024-11-10 22:36:11]
  • hack成功,自动添加数据
  • (/hack/1163)
  • [2024-11-06 21:49:58]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:872ms
  • 内存:30420kb
  • [2024-11-06 21:48:00]
  • hack成功,自动添加数据
  • (/hack/1142)
  • [2024-11-05 13:38:39]
  • 评测
  • 测评结果:100
  • 用时:932ms
  • 内存:31112kb
  • [2024-11-05 13:38:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+9;
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an,cn,fac[1000001],inv[1000001],st[1000001],u[1000001];
char s[3][1000001],s1[3][1000001];
long long hs[3][1000001],base[1000001];
struct p{long long q,w;}l[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
long long get(long long qq,long long ww,long long ee)
{
	return ((hs[ee][ww]-hs[ee][qq-1]*base[ww-qq+1])%mod+mod)%mod;
}
void work()
{
	for(int i=a;i>=2;i--)
	{
		if(i*2<=an) break;
		cn=0;
		for(int j=i;j<=a;j+=i) st[++cn]=j;
		st[cn+1]=st[cn]+i;
		for(int j=1;j<=cn-1;j++)
		{
			long long t1=st[j];
			long long t2=st[j+1];
			long long ll=1,rr=t1,an1=t1+1;
			ll=max(ll,st[j-1]-1);
			while(ll<=rr)
			{
				long long mid=((ll+rr)>>1);
				if(get(mid,t1,1)==get(t2-(t1-mid),t2,1)) an1=mid,rr=mid-1;
				else ll=mid+1;
			}
			long long an2=t1,ls2=t2;
			ll=t2+1,rr=a;rr=min(rr,st[j+2]+1);
			while(ll<=rr)
			{
				long long mid=((ll+rr)>>1);
				if(get(t1+1,t1+(mid-t2),1)==get(t2+1,mid,1)) an2=t1+(mid-t2),ls2=mid,ll=mid+1;
				else rr=mid-1;
			}
			ll=ls2,rr=a;rr=min(rr,st[j+2]+1);
			long long an3=an2;
			while(ll<=rr)
			{
				long long mid=((ll+rr)>>1);
				if(get(an2+1,an2+mid-ls2+1,1)==get(ls2,mid,2)) an3=an2+mid-ls2+1,ll=mid+1;
				else rr=mid-1;
			}
			an1=t2-(t1-an1);
			if(an1-1<=an3) an=max(an,(long long)(i*2));
		}
		for(int j=1;j<=cn;j++)
		{
			long long t1=st[j];
			long long t2=st[j+1]-1;
			if(t2>a) break;
			long long ll=1,rr=t1,an1=t1+1;
			ll=max(ll,st[j-1]-1);
			while(ll<=rr)
			{
				long long mid=((ll+rr)>>1);
				if(get(mid,t1,1)==get(t2-(t1-mid),t2,2)) an1=mid,rr=mid-1;
				else ll=mid+1;
			}
			long long an2=t1;
			ll=t2+1,rr=a;
			rr=min(rr,st[j+1]+1);
			while(ll<=rr)
			{
				long long mid=((ll+rr)>>1);
				if(get(t1+1,t1+(mid-t2),1)==get(t2+1,mid,2)) an2=t1+(mid-t2),ll=mid+1;
				else rr=mid-1;
			}
			long long ls1=an1;
			an1=t2-(t1-an1);
			if(an1<=an2)
			{
				an=max(an,(long long)(i*2));
			}
			else
			{
				long long l1=an2+1,r1=an1;
				long long r2=ls1-1;
				long long l2=r2-(r1-l1);
				if(l2>=1&&get(l1,r1,1)==get(l2,r2,1)) an=max(an,(long long)(i*2));
			}
		}
	}
}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	scanf("%lld",&a);
	for(int i=1;i<=2;i++)
	{
		scanf("%s",s[i]+1);
	}
	base[0]=1;
	for(int i=1;i<=1000000;i++) base[i]=base[i-1]*233%mod;
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<=a;j++) hs[i][j]=(hs[i][j-1]*233+s[i][j])%mod;
	}
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<a;j++)
		{
			if(s[i][j]==s[i][j+1]) an=2;
		}
	}
//	cout<<get(1,3,1)<<" "<<get(4,6,1);return 0;
	for(int i=1;i<=a;i++) if(s[1][i]==s[2][i]) an=2;
//	for(int i=1;i<=2;i++) work1(i);
	work();
	for(int i=1;i<=2;i++) for(int j=1;j<=a;j++) s1[i][j]=s[i][j];
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<=a;j++) s[3-i][a-j+1]=s1[i][j];
	}
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<=a;j++) hs[i][j]=(hs[i][j-1]*233+s[i][j])%mod;
	}
	work();
	printf("%lld",an);
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 24296kb

input:

5
abcab
acabc

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 3ms
memory: 22392kb

input:

6
babbaa
babaaa

output:

6

result:

ok single line: '6'

Test #3:

score: 0
Accepted
time: 3ms
memory: 22280kb

input:

2
ne
fu

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 3ms
memory: 22392kb

input:

6
baabba
baabab

output:

4

result:

ok single line: '4'

Test #5:

score: 0
Accepted
time: 3ms
memory: 24372kb

input:

6
aaabba
aabbba

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 3ms
memory: 24356kb

input:

6
abaabb
bbbaba

output:

4

result:

ok single line: '4'

Test #7:

score: 0
Accepted
time: 413ms
memory: 28844kb

input:

200000
wvblpxtatzytphgshchrevqqpnbljlorfoqubygysrivtemegmgrepemnlcbfqalpqqpvuockkbbvjnouhcerxqibevbipsxuscjejlcdtxoxipwrfrjwnriubvdgdgzlydwwiueovtrzljqxwfegejukncmahbcbsraxboukdesrzbwfvbpxpdntauidrybccwaocfwntohdkhxkfqhnoccyaylvvfebckmslrthubxrxvjoqcredanofbmgtsnswgszwhjckqeiddzvpnxphjkrwlsbthdvhzgn...

output:

200000

result:

ok single line: '200000'

Test #8:

score: 0
Accepted
time: 14ms
memory: 29244kb

input:

199999
klwumjcvuqinrkcsyvgfixhwvrwbmazkclblcnlpyxtlmmpkllkpukmxaurpukvgibcsuigcoqnnreivrlrwfdqofqcwubpolnnxcansyaevdjvnhnzvjeoejktaodusltockhtuqrohqfsrezdzurowghmcateztzlltkzlqynxpgbqsvgqtpukmfgdxopynqaegmjxvjixyzjrhbgahxwkswgpanhrdgpyvtvcpsihdvmtixfskuiprfqrfknohthfblkzlrcyqewdycoljgwrhjkmoxqmtogmg...

output:

200000

result:

ok single line: '200000'

Test #9:

score: 0
Accepted
time: 431ms
memory: 29068kb

input:

200000
yagcbqaxecsgdijvsdsqlemrrhyyuysvlbkkgultlmrapzokempkzmyyvgabgtqifgqhwyudzbkbjncsuixvyffpvtuczjakknocyskvqaohfvxomjhzirykpdwisgkmyomejaxbzamrnfcxjwjouskvjfuriurzknmhfvpvbdqunfckdmxhndvffhuybezncgohzwxvwfscltbhwvgvbrrejtuixsdwetkdxlogepphsvhyzybisqixsledftgegzbslkqsalhoifysrxsbjxvpojjxkqqoumlkj...

output:

114514

result:

ok single line: '114514'

Test #10:

score: 0
Accepted
time: 872ms
memory: 30420kb

input:

200000
cbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbabcbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbabcbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbabcbaca...

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 22ms
memory: 28120kb

input:

200000
bbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbaba...

output:

150050

result:

ok single line: '150050'

Test #12:

score: 0
Accepted
time: 34ms
memory: 29292kb

input:

200000
babababbaaaaaaabbbaaabbbbaaabbaaaabbaababbabbbbbababbbabbbaaabaaabaabbaabbaabbabbaaaaaababbbbbbaaaabaababbabaaabbbbbbabaaaabaaabaaaababaaabbbbbbaaabaabaaabbabbbabbbabaaaabbbbbbabbaabbaaaaaaaaabababbabbbbbaabaabaaabababbaabbbbbbabbaaaaababaabbaaaabbbbaaababbabbaabaabaabaaabbabaaaaabbabababbbaa...

output:

131072

result:

ok single line: '131072'

Test #13:

score: 0
Accepted
time: 818ms
memory: 30228kb

input:

200000
rhqtphowacdrsxqisrqjhcsmxvwqtbmsvawxxxujgibnowkeyzhnjihsvsuklueukevgvlfqnrhalhglqlknerjwzizhxxszwjtnroubsjdhbnekbolwxaigyeypumuncdhmqqeljoyewehkhsqfoirchdnwazypwtefdyvtockpluejsftmffgbgdcotjnnkimawpflzwurdwrmpeudobzhpoyktufkgyvxpbfhuzswkrmnfzultfxdefoffvrfmuoufylyfvexnxgwgqfbiqvwpyenoqxncisuz...

output:

8

result:

ok single line: '8'

Test #14:

score: 0
Accepted
time: 4ms
memory: 24292kb

input:

10
aaabaabaaa
aabbbaaaba

output:

6

result:

ok single line: '6'

Test #15:

score: 0
Accepted
time: 0ms
memory: 24260kb

input:

17
ababbbaabbbaaaaba
abbabbbbbaabaabba

output:

10

result:

ok single line: '10'

Test #16:

score: 0
Accepted
time: 4ms
memory: 24372kb

input:

22
aaabbbaaaababbabbbbbbb
bbaabbbbbaaabbbabaaaaa

output:

8

result:

ok single line: '8'

Test #17:

score: 0
Accepted
time: 3ms
memory: 24356kb

input:

15
abaabaaaaabbbab
abbbabbbabababa

output:

8

result:

ok single line: '8'

Test #18:

score: 0
Accepted
time: 0ms
memory: 22308kb

input:

5
aabba
baaba

output:

6

result:

ok single line: '6'

Test #19:

score: 0
Accepted
time: 3ms
memory: 20276kb

input:

1
a
a

output:

2

result:

ok single line: '2'

Test #20:

score: 0
Accepted
time: 6ms
memory: 24440kb

input:

100
baabaaaabaabaabaaabaabbbabbbbbaababbabbbabbbbababaaabbabbaaaabbbaaabaabbbaaaaaababaababbbbbaaabbaabb
abbbbbbbbaaaaababbabbabbbbbaaaabbabbbaaaaabababbbabbababbbabbaabbabbabbbaaababbabbabbabbbabbbababaaa

output:

20

result:

ok single line: '20'

Test #21:

score: 0
Accepted
time: 3ms
memory: 22328kb

input:

32
babbbbbabbababaabbbaaaaabbaababa
abbbaaababaabababbaaabaaabbaaaab

output:

18

result:

ok single line: '18'

Extra Test:

score: 0
Extra Test Passed