結果

問題 No.599 回文かい
ユーザー rlangevinrlangevin
提出日時 2023-10-18 08:59:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 984 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,380 KB
最終ジャッジ日時 2023-10-18 08:59:19
合計ジャッジ時間 7,492 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,620 KB
testcase_01 AC 46 ms
55,572 KB
testcase_02 AC 45 ms
55,576 KB
testcase_03 AC 45 ms
55,576 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
evil_0.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
from functools import lru_cache

@lru_cache(maxsize=None)
def f(start, goal):
    val = 1
    ind = 1
    while start + ind < goal - ind:
        if R.get(start, start + ind) == R.get(goal - ind, goal):
            val += f(start + ind, goal - ind)
        ind += 1  
    return val

class RollingHash():
    def __init__(self, s):
        self._mod = 2 ** 64 - 1
        self._base = 4649
        
        n = len(s)
        self.h = [0] * (n + 1)
        self.pw = [1] * (n + 1)
 
        for i in range(n):
            self.h[i + 1] = self.h[i] * self._base + ord(s[i])
            self.h[i + 1] %= self._mod
 
        for i in range(n):
            self.pw[i + 1] = self.pw[i] * self._base
            self.pw[i + 1] %= self._mod
            
        """
        s[l:r]のhash値
        """
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r - l]) % self._mod
    
S = input()
R = RollingHash(S)
print(f(0, len(S)))
0