結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,536 KB
testcase_01 AC 45 ms
55,536 KB
testcase_02 AC 46 ms
55,536 KB
testcase_03 AC 45 ms
55,536 KB
testcase_04 AC 57 ms
65,888 KB
testcase_05 AC 83 ms
76,416 KB
testcase_06 AC 46 ms
55,536 KB
testcase_07 AC 47 ms
57,584 KB
testcase_08 AC 47 ms
57,584 KB
testcase_09 AC 64 ms
70,628 KB
testcase_10 AC 86 ms
76,952 KB
testcase_11 AC 85 ms
76,680 KB
testcase_12 AC 117 ms
77,092 KB
testcase_13 AC 151 ms
77,320 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

@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 = input()
R = RollingHash(S)
print(f(0, len(S)))
0