結果

問題 No.765 ukuku 2
ユーザー mkawa2mkawa2
提出日時 2022-02-08 13:02:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,233 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 127,784 KB
最終ジャッジ日時 2023-09-05 10:41:37
合計ジャッジ時間 10,240 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
76,596 KB
testcase_01 AC 89 ms
72,188 KB
testcase_02 AC 88 ms
71,900 KB
testcase_03 AC 87 ms
72,072 KB
testcase_04 AC 88 ms
71,904 KB
testcase_05 AC 88 ms
71,944 KB
testcase_06 AC 89 ms
72,092 KB
testcase_07 AC 91 ms
71,908 KB
testcase_08 AC 88 ms
71,912 KB
testcase_09 AC 89 ms
72,068 KB
testcase_10 AC 88 ms
72,420 KB
testcase_11 AC 89 ms
72,148 KB
testcase_12 AC 89 ms
72,292 KB
testcase_13 AC 93 ms
72,044 KB
testcase_14 AC 90 ms
72,144 KB
testcase_15 AC 91 ms
72,108 KB
testcase_16 AC 91 ms
71,904 KB
testcase_17 AC 90 ms
72,040 KB
testcase_18 AC 97 ms
76,892 KB
testcase_19 AC 95 ms
72,140 KB
testcase_20 AC 90 ms
71,904 KB
testcase_21 AC 94 ms
77,188 KB
testcase_22 AC 95 ms
76,796 KB
testcase_23 AC 92 ms
76,760 KB
testcase_24 AC 100 ms
77,012 KB
testcase_25 AC 98 ms
76,056 KB
testcase_26 AC 117 ms
77,692 KB
testcase_27 AC 113 ms
77,784 KB
testcase_28 AC 118 ms
77,800 KB
testcase_29 AC 116 ms
77,804 KB
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = (1 << 63)-1
inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

from random import randrange

class RollingHash:
    def __init__(self, target, BASE):
        self.BASE = BASE
        self.MOD = (1 << 61)-1
        self.N = len(target)
        self.table = [0]
        self.power = [1]
        for c in target:
            self.table += [self._mod(self.table[-1]*self.BASE)+ord(c)]
            self.power += [self._mod(self.power[-1]*self.BASE)]

    def _mod(self, a):
        a = (a >> 61)+(a & self.MOD)
        if a >= self.MOD: return a-self.MOD
        return a

    def hashing(self, s):
        h = 0
        for c in s:
            h = self._mod(h*self.BASE)+ord(c)
        return self._mod(h)

    def hash_lr(self, l, r):
        return self._mod(self.table[r]-self._mod(self.table[l]*self.power[r-l]))

    def find(self, s, start=0):
        h = self.hashing(s)
        for i in range(start, self.N-len(s)+1):
            if self.hash_lr(i, i+len(s)) == h:
                return i
        return -1

    def find_all(self, s):
        res = []
        h = self.hashing(s)
        for i in range(self.N-len(s)+1):
            if self.hash_lr(i, i+len(s)) == h:
                res.append(i)
        return res

def binary_search(l, r, ok, minimize, i, j):
    if minimize: l -= 1
    else: r += 1
    while l+1 < r:
        m = (l+r)//2
        if ok(m, i, j) ^ minimize: l = m
        else: r = m
    if minimize: return r
    return l

def ok(d, i, j):
    if i-d < 0 or j+d > n: return False
    return h.hash_lr(i-d, i) == rh.hash_lr(n-(j+d), n-j)

s = SI()
n = len(s)
BASE = randrange(128, 256)
h = RollingHash(s, BASE)
rh = RollingHash(s[::-1], BASE)

ans = 1
for i in range(1, n):
    d = binary_search(0, min(i, n-i), ok, False, i, i)
    if d*2 == n:
        print(n-1)
        exit()
    # delete left
    ni, nj = i-d-1, i+d
    if ni >= 0:
        e = binary_search(0, min(ni, n-nj), ok, False, ni, nj)
        ans = max(ans, (d+e)*2)
    # delete right
    ni, nj = i-d, i+d+1
    if nj <= n:
        e = binary_search(0, min(ni, n-nj), ok, False, ni, nj)
        ans = max(ans, (d+e)*2)

for i in range(n-1):
    d = binary_search(0, min(i, n-i), ok, False, i, i+1)
    if d*2+1 == n:
        print(n-1)
        exit()
    # delete left
    ni, nj = i-d-1, i+1+d
    if ni >= 0:
        e = binary_search(0, min(ni, n-nj), ok, False, ni, nj)
        ans = max(ans, (d+e)*2+1)
    # delete right
    ni, nj = i-d, i+d+2
    if nj <= n:
        e = binary_search(0, min(ni, n-nj), ok, False, ni, nj)
        ans = max(ans, (d+e)*2+1)

print(ans)
0