QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#711825 | #9522. A Simple String Problem | xyz123# | AC ✓ | 881ms | 31216kb | C++23 | 3.7kb | 2024-11-05 13:38:38 | 2024-11-10 22:38:17 |
Judging History
你现在查看的是最新测评结果
- [2024-11-10 22:36:11]
- hack成功,自动添加数据
- (/hack/1163)
- [2024-11-06 21:48:00]
- hack成功,自动添加数据
- (/hack/1142)
- [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,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 24448kb
input:
5 abcab acabc
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 2ms
memory: 24336kb
input:
6 babbaa babaaa
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Accepted
time: 3ms
memory: 22276kb
input:
2 ne fu
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 4ms
memory: 24392kb
input:
6 baabba baabab
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 7ms
memory: 24376kb
input:
6 aaabba aabbba
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 24268kb
input:
6 abaabb bbbaba
output:
4
result:
ok single line: '4'
Test #7:
score: 0
Accepted
time: 413ms
memory: 31216kb
input:
200000 wvblpxtatzytphgshchrevqqpnbljlorfoqubygysrivtemegmgrepemnlcbfqalpqqpvuockkbbvjnouhcerxqibevbipsxuscjejlcdtxoxipwrfrjwnriubvdgdgzlydwwiueovtrzljqxwfegejukncmahbcbsraxboukdesrzbwfvbpxpdntauidrybccwaocfwntohdkhxkfqhnoccyaylvvfebckmslrthubxrxvjoqcredanofbmgtsnswgszwhjckqeiddzvpnxphjkrwlsbthdvhzgn...
output:
200000
result:
ok single line: '200000'
Test #8:
score: 0
Accepted
time: 11ms
memory: 29272kb
input:
199999 klwumjcvuqinrkcsyvgfixhwvrwbmazkclblcnlpyxtlmmpkllkpukmxaurpukvgibcsuigcoqnnreivrlrwfdqofqcwubpolnnxcansyaevdjvnhnzvjeoejktaodusltockhtuqrohqfsrezdzurowghmcateztzlltkzlqynxpgbqsvgqtpukmfgdxopynqaegmjxvjixyzjrhbgahxwkswgpanhrdgpyvtvcpsihdvmtixfskuiprfqrfknohthfblkzlrcyqewdycoljgwrhjkmoxqmtogmg...
output:
200000
result:
ok single line: '200000'
Test #9:
score: 0
Accepted
time: 432ms
memory: 28068kb
input:
200000 yagcbqaxecsgdijvsdsqlemrrhyyuysvlbkkgultlmrapzokempkzmyyvgabgtqifgqhwyudzbkbjncsuixvyffpvtuczjakknocyskvqaohfvxomjhzirykpdwisgkmyomejaxbzamrnfcxjwjouskvjfuriurzknmhfvpvbdqunfckdmxhndvffhuybezncgohzwxvwfscltbhwvgvbrrejtuixsdwetkdxlogepphsvhyzybisqixsledftgegzbslkqsalhoifysrxsbjxvpojjxkqqoumlkj...
output:
114514
result:
ok single line: '114514'
Test #10:
score: 0
Accepted
time: 881ms
memory: 25404kb
input:
200000 cbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbabcbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbabcbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbabcbaca...
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 23ms
memory: 29196kb
input:
200000 bbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbaba...
output:
150050
result:
ok single line: '150050'
Test #12:
score: 0
Accepted
time: 31ms
memory: 30520kb
input:
200000 babababbaaaaaaabbbaaabbbbaaabbaaaabbaababbabbbbbababbbabbbaaabaaabaabbaabbaabbabbaaaaaababbbbbbaaaabaababbabaaabbbbbbabaaaabaaabaaaababaaabbbbbbaaabaabaaabbabbbabbbabaaaabbbbbbabbaabbaaaaaaaaabababbabbbbbaabaabaaabababbaabbbbbbabbaaaaababaabbaaaabbbbaaababbabbaabaabaabaaabbabaaaaabbabababbbaa...
output:
131072
result:
ok single line: '131072'
Test #13:
score: 0
Accepted
time: 804ms
memory: 27884kb
input:
200000 rhqtphowacdrsxqisrqjhcsmxvwqtbmsvawxxxujgibnowkeyzhnjihsvsuklueukevgvlfqnrhalhglqlknerjwzizhxxszwjtnroubsjdhbnekbolwxaigyeypumuncdhmqqeljoyewehkhsqfoirchdnwazypwtefdyvtockpluejsftmffgbgdcotjnnkimawpflzwurdwrmpeudobzhpoyktufkgyvxpbfhuzswkrmnfzultfxdefoffvrfmuoufylyfvexnxgwgqfbiqvwpyenoqxncisuz...
output:
8
result:
ok single line: '8'
Test #14:
score: 0
Accepted
time: 2ms
memory: 24384kb
input:
10 aaabaabaaa aabbbaaaba
output:
6
result:
ok single line: '6'
Test #15:
score: 0
Accepted
time: 3ms
memory: 24440kb
input:
17 ababbbaabbbaaaaba abbabbbbbaabaabba
output:
10
result:
ok single line: '10'
Test #16:
score: 0
Accepted
time: 3ms
memory: 22352kb
input:
22 aaabbbaaaababbabbbbbbb bbaabbbbbaaabbbabaaaaa
output:
8
result:
ok single line: '8'
Test #17:
score: 0
Accepted
time: 0ms
memory: 24448kb
input:
15 abaabaaaaabbbab abbbabbbabababa
output:
8
result:
ok single line: '8'
Test #18:
score: 0
Accepted
time: 4ms
memory: 24268kb
input:
5 aabba baaba
output:
6
result:
ok single line: '6'
Test #19:
score: 0
Accepted
time: 3ms
memory: 20352kb
input:
1 a a
output:
2
result:
ok single line: '2'
Test #20:
score: 0
Accepted
time: 7ms
memory: 22356kb
input:
100 baabaaaabaabaabaaabaabbbabbbbbaababbabbbabbbbababaaabbabbaaaabbbaaabaabbbaaaaaababaababbbbbaaabbaabb abbbbbbbbaaaaababbabbabbbbbaaaabbabbbaaaaabababbbabbababbbabbaabbabbabbbaaababbabbabbabbbabbbababaaa
output:
20
result:
ok single line: '20'
Test #21:
score: 0
Accepted
time: 8ms
memory: 24400kb
input:
32 babbbbbabbababaabbbaaaaabbaababa abbbaaababaabababbaaabaaabbaaaab
output:
18
result:
ok single line: '18'
Extra Test:
score: 0
Extra Test Passed