結果

問題 No.765 ukuku 2
ユーザー mkawa2mkawa2
提出日時 2022-02-08 16:40:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,161 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 82,144 KB
実行使用メモリ 101,652 KB
最終ジャッジ日時 2024-06-23 11:45:27
合計ジャッジ時間 55,521 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
56,680 KB
testcase_01 AC 40 ms
55,692 KB
testcase_02 AC 41 ms
55,080 KB
testcase_03 AC 44 ms
55,020 KB
testcase_04 AC 41 ms
55,640 KB
testcase_05 AC 41 ms
55,940 KB
testcase_06 AC 41 ms
56,296 KB
testcase_07 AC 40 ms
55,088 KB
testcase_08 AC 42 ms
55,292 KB
testcase_09 AC 43 ms
56,440 KB
testcase_10 AC 41 ms
55,916 KB
testcase_11 AC 42 ms
56,584 KB
testcase_12 AC 42 ms
54,936 KB
testcase_13 AC 41 ms
55,876 KB
testcase_14 AC 42 ms
55,392 KB
testcase_15 AC 43 ms
55,168 KB
testcase_16 AC 41 ms
56,388 KB
testcase_17 AC 43 ms
56,648 KB
testcase_18 AC 47 ms
62,784 KB
testcase_19 AC 41 ms
55,580 KB
testcase_20 AC 43 ms
57,284 KB
testcase_21 AC 45 ms
61,484 KB
testcase_22 AC 46 ms
62,148 KB
testcase_23 AC 46 ms
62,024 KB
testcase_24 AC 48 ms
63,948 KB
testcase_25 AC 46 ms
62,268 KB
testcase_26 AC 58 ms
69,284 KB
testcase_27 AC 59 ms
69,076 KB
testcase_28 AC 57 ms
69,528 KB
testcase_29 AC 59 ms
69,504 KB
testcase_30 AC 2,378 ms
95,108 KB
testcase_31 AC 2,320 ms
94,912 KB
testcase_32 AC 2,180 ms
94,044 KB
testcase_33 AC 465 ms
99,128 KB
testcase_34 AC 1,027 ms
99,252 KB
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 AC 2,409 ms
94,768 KB
testcase_41 AC 2,628 ms
95,928 KB
testcase_42 AC 2,786 ms
98,400 KB
testcase_43 AC 2,524 ms
96,128 KB
testcase_44 AC 2,527 ms
96,256 KB
testcase_45 AC 2,831 ms
95,440 KB
testcase_46 AC 2,464 ms
94,812 KB
testcase_47 AC 2,888 ms
97,136 KB
testcase_48 AC 2,833 ms
96,032 KB
testcase_49 AC 2,844 ms
96,292 KB
権限があれば一括ダウンロードができます

ソースコード

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):
        return a%self.MOD

    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