結果

問題 No.599 回文かい
ユーザー rlangevinrlangevin
提出日時 2023-10-18 12:04:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,026 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,060 KB
実行使用メモリ 19,140 KB
最終ジャッジ日時 2023-10-18 12:04:54
合計ジャッジ時間 6,772 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,148 KB
testcase_01 AC 32 ms
10,148 KB
testcase_02 AC 31 ms
10,148 KB
testcase_03 AC 30 ms
10,148 KB
testcase_04 AC 32 ms
10,160 KB
testcase_05 AC 42 ms
10,168 KB
testcase_06 AC 31 ms
10,156 KB
testcase_07 AC 31 ms
10,160 KB
testcase_08 AC 30 ms
10,160 KB
testcase_09 AC 34 ms
10,152 KB
testcase_10 AC 56 ms
10,864 KB
testcase_11 AC 54 ms
10,676 KB
testcase_12 AC 106 ms
10,916 KB
testcase_13 AC 163 ms
10,728 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