結果
| 問題 | 
                            No.599 回文かい
                             | 
                    
| コンテスト | |
| ユーザー | 
                             gew1fw
                         | 
                    
| 提出日時 | 2025-06-12 20:25:04 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,243 bytes | 
| コンパイル時間 | 280 ms | 
| コンパイル使用メモリ | 82,096 KB | 
| 実行使用メモリ | 76,248 KB | 
| 最終ジャッジ日時 | 2025-06-12 20:25:24 | 
| 合計ジャッジ時間 | 18,462 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 7 WA * 15 | 
ソースコード
MOD = 10**9 + 7
def count_palindromic_decompositions(S):
    n = len(S)
    if n == 0:
        return 0
    
    # Precompute prefix hashes and power array
    base = 911382629
    mod = 10**18 + 3
    prefix_hash = [0] * (n + 1)
    power = [1] * (n + 1)
    
    for i in range(n):
        prefix_hash[i+1] = (prefix_hash[i] * base + ord(S[i])) % mod
        power[i+1] = (power[i] * base) % mod
    
    dp = [0] * (n + 1)
    dp[0] = 1
    
    for i in range(1, n + 1):
        dp[i] = 1  # The case where the entire substring is a single part
        
        max_l = i // 2
        for l in range(1, max_l + 1):
            if i - l < 0:
                continue  # Not possible
            
            # Compute hash of first l characters
            hash_first = prefix_hash[l]
            
            # Compute hash of substring S[i-l ... i)
            hash_sub = (prefix_hash[i] - prefix_hash[i - l] * power[l]) % mod
            if hash_sub < 0:
                hash_sub += mod
            
            if hash_first == hash_sub:
                if i - 2 * l >= 0:
                    dp[i] = (dp[i] + dp[i - 2 * l]) % MOD
    
    return dp[n] % MOD
# Read input
S = input().strip()
print(count_palindromic_decompositions(S))
            
            
            
        
            
gew1fw