2016-05-18~21:資料
745 ワード
問題を書き直す
# abacabcaba -> ^#a#b#a#c#a#b#c#a#b#a#$
# r: ,c:
def manacher(_s):
s = '#'.join('^{}$'.format(_s))
c,r,n = 0,0,len(s)
p = n*[0]
for i in xrange(1,n-1):
if rr: #
c,r = i,p[i]+i
maxl,maxi = max((n,i) for i,n in enumerate(p)) #
return _s[(maxi-maxl)/2:(maxi+maxl)/2]
print manacher('abacabcaba')