結果

問題 No.599 回文かい
ユーザー rlangevinrlangevin
提出日時 2023-10-18 12:12:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,194 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 96,764 KB
最終ジャッジ日時 2023-10-18 12:12:34
合計ジャッジ時間 7,090 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,676 KB
testcase_01 AC 46 ms
55,552 KB
testcase_02 AC 45 ms
55,552 KB
testcase_03 AC 46 ms
55,552 KB
testcase_04 AC 64 ms
67,952 KB
testcase_05 AC 85 ms
76,492 KB
testcase_06 AC 46 ms
55,552 KB
testcase_07 AC 47 ms
57,600 KB
testcase_08 AC 48 ms
57,600 KB
testcase_09 AC 65 ms
70,672 KB
testcase_10 AC 87 ms
77,304 KB
testcase_11 AC 87 ms
76,972 KB
testcase_12 AC 117 ms
77,448 KB
testcase_13 AC 153 ms
77,584 KB
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
mod = 10 ** 9 + 7

def main():
    @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)
                val %= mod
            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 = list(input())
    R = RollingHash(S)
    print(f(0, len(S)))

main()
0