結果
| 問題 | 
                            No.1646 Avoid Palindrome
                             | 
                    
| コンテスト | |
| ユーザー | 
                             sotanishy
                         | 
                    
| 提出日時 | 2021-08-14 22:52:14 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 824 bytes | 
| コンパイル時間 | 314 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 81,024 KB | 
| 最終ジャッジ日時 | 2024-10-06 00:32:05 | 
| 合計ジャッジ時間 | 17,860 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 1 TLE * 4 -- * 35 | 
ソースコード
import sys
input = sys.stdin.readline
mod = 998244353
N = int(input())
S = input().rstrip()
if N == 1:
    if S[0] == '?':
        print(26)
    else:
        print(1)
    exit()
dp = [0] * (26**2)
for a in range(26):
    if S[0] != '?' and S[0] != chr(ord('a') + a):
        continue
    for b in range(26):
        if S[1] != '?' and S[1] != chr(ord('a') + b):
            continue
        if a != b:
            dp[26*a + b] = 1
for i in range(2, N):
    ndp = [0] * (26**2)
    for j in range(26):
        if S[i] != '?' and S[i] != chr(ord('a') + j):
            continue
        for k in range(26**2):
            a, b = divmod(k, 26)
            if a != j and b != j:
                ndp[26*b + j] = (ndp[26*b + j] + dp[k]) % mod
    dp = ndp
ans = 0
for i in range(26**2):
    ans = (ans + dp[i]) % mod
print(ans)
            
            
            
        
            
sotanishy