結果

問題 No.765 ukuku 2
ユーザー mkawa2mkawa2
提出日時 2022-02-08 13:02:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,233 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 116,316 KB
最終ジャッジ日時 2024-06-23 06:24:45
合計ジャッジ時間 6,952 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
59,904 KB
testcase_01 AC 41 ms
54,656 KB
testcase_02 AC 40 ms
54,784 KB
testcase_03 AC 41 ms
54,528 KB
testcase_04 AC 40 ms
54,656 KB
testcase_05 AC 40 ms
54,656 KB
testcase_06 AC 41 ms
54,528 KB
testcase_07 AC 41 ms
55,168 KB
testcase_08 AC 40 ms
54,784 KB
testcase_09 AC 42 ms
55,936 KB
testcase_10 AC 46 ms
54,784 KB
testcase_11 AC 43 ms
54,912 KB
testcase_12 AC 42 ms
54,912 KB
testcase_13 AC 42 ms
55,040 KB
testcase_14 AC 43 ms
55,296 KB
testcase_15 AC 42 ms
55,168 KB
testcase_16 AC 42 ms
55,296 KB
testcase_17 AC 42 ms
55,808 KB
testcase_18 AC 49 ms
62,848 KB
testcase_19 AC 43 ms
55,040 KB
testcase_20 AC 44 ms
55,296 KB
testcase_21 AC 49 ms
61,952 KB
testcase_22 AC 48 ms
61,568 KB
testcase_23 AC 48 ms
61,824 KB
testcase_24 AC 48 ms
62,720 KB
testcase_25 AC 47 ms
61,056 KB
testcase_26 AC 68 ms
71,808 KB
testcase_27 AC 69 ms
71,808 KB
testcase_28 AC 71 ms
72,192 KB
testcase_29 AC 69 ms
71,808 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