QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#562017 | #8668. 回文路径 | hhiron | 0 | 74ms | 20292kb | C++14 | 1.4kb | 2024-09-13 14:16:46 | 2024-09-13 14:16:46 |
Judging History
answer
#include<bits/stdc++.h>
#define INF 0x7fffffff
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=5e5+5;
int n;
ull has1l[N],has2l[N],has1r[N],has2r[N],po[N];
string a,b,s1,s2;
inline ull gethash(int x,int y,ull *has){
return (has[y]-has[x]*po[abs(x-y)]);
}int ans=0;
void solve(){
has1l[0]=s1[0]-'a',has2l[0]=s2[0]-'a';
cout<<s1<<endl<<s2<<endl;
for(int i=1;i<=n+1;i++) has1l[i]=has1l[i-1]*31+s1[i]-'a';
for(int i=n+1;i>=0;i--) has1r[i]=has1r[i+1]*31+s1[i]-'a';
for(int i=1;i<=n+1;i++) has2l[i]=has2l[i-1]*31+s2[i]-'a';
for(int i=n+1;i>=0;i--) has2r[i]=has2r[i+1]*31+s2[i]-'a';
for(int i=1;i<=n;i++){
int l=0,r=min(n,n-i)+1;
while(r-l>1){
int mid=(l+r)>>1;
if(gethash(i-mid,i+mid,has1l)==gethash(i+mid,i-mid,has1r)) l=mid;
else r=mid;
}int lrc=(l*2+1)/2;
int posl=i-l-1,posr=i+l-1;
l=-1,r=min(posl,n-posr)+1;
while(r-l>1){
int mid=(l+r)>>1;
if(gethash(posl,posl-mid,has1r)==gethash(posr,posr+mid,has2l)) l=mid;
else r=mid;
}ans=max(ans,lrc);
// cout<<i<<" "<<s1[i]<<" "<<l<<endl;
}
}
int main(){
cin>>n>>a>>b;
po[0]=1;
for(int i=1;i<=n*4;i++) po[i]=po[i-1]*31;
a=" "+a;
b=" "+b;
s1+='?',s2+='?';
for(int i=1;i<=n;i++){
s1+='#',s2+='#';
s1+=a[i],s2+=b[i];
}s1+='#',s2+='#',s1+='~',s2+='~';
n=n*2+1;
solve();
swap(s1,s2);
reverse(s1.begin(),s1.end()); reverse(s2.begin(),s2.end());
solve();
cout<<ans;
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: 2ms
memory: 7944kb
input:
1000 mfmlkrasfiudkzrjzyrlbpitvzfrlmjdzsurtdcmnqpsyfgobbstvplqylvciloomaljyssxtrrccywyirfvlcnchwkfwbdaoxzpfpvlruptganojnfxmnlqetptmlmoyluxvaipghtlaszoozscdmjomobyzboqqmvqjpbfjsoczhkwrlcauzjceqikbaeuiqahnldpqmohfjfzgkbfdbqnoxispkejvpncwsyelebqumapgbfdrjvuaxaphnkciwzkruijmanwslkwosgyfhwbnsthhtxrhrzlgtt...
output:
?#m#f#m#l#k#r#a#s#f#i#u#d#k#z#r#j#z#y#r#l#b#p#i#t#v#z#f#r#l#m#j#d#z#s#u#r#t#d#c#m#n#q#p#s#y#f#g#o#b#b#s#t#v#p#l#q#y#l#v#c#i#l#o#o#m#a#l#j#y#s#s#x#t#r#r#c#c#y#w#y#i#r#f#v#l#c#n#c#h#w#k#f#w#b#d#a#o#x#z#p#f#p#v#l#r#u#p#t#g#a#n#o#j#n#f#x#m#n#l#q#e#t#p#t#m#l#m#o#y#l#u#x#v#a#i#p#g#h#t#l#a#s#z#o#o#z#s#c#d#...
result:
wrong answer 1st lines differ - expected: '6', found: '?#m#f#m#l#k#r#a#s#f#i#u#d#k#z#...o#h#f#v#y#v#g#r#p#x#t#m#d#v#e#~'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 74ms
memory: 20292kb
input:
100000 ibhqhodaqcwqggmckoemulhkgbfidceskhefhsonccepfodalabaqgobpgcnaervbccadkbtsdigsoqochklocgbjjqcdhwrlacamprsoilyhiwkkjalicedhbxajrkhjgivjhnfdibkdwtexnnriegejazmohlfijbeigfmpngncokxhifjfuwuogccdfglfbxobnarmgfhgpnjjewicgfhcmfbbnjbbjjtbprnagpchcihcihfhcikeaecefdgeegtzlfdolhfieahiehdfcaflmndmcojceblf...
output:
?#i#b#h#q#h#o#d#a#q#c#w#q#g#g#m#c#k#o#e#m#u#l#h#k#g#b#f#i#d#c#e#s#k#h#e#f#h#s#o#n#c#c#e#p#f#o#d#a#l#a#b#a#q#g#o#b#p#g#c#n#a#e#r#v#b#c#c#a#d#k#b#t#s#d#i#g#s#o#q#o#c#h#k#l#o#c#g#b#j#j#q#c#d#h#w#r#l#a#c#a#m#p#r#s#o#i#l#y#h#i#w#k#k#j#a#l#i#c#e#d#h#b#x#a#j#r#k#h#j#g#i#v#j#h#n#f#d#i#b#k#d#w#t#e#x#n#n#r#i#...
result:
wrong answer 1st lines differ - expected: '9', found: '?#i#b#h#q#h#o#d#a#q#c#w#q#g#g#...l#h#m#e#e#f#b#n#u#k#v#v#e#h#k#~'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%