結果
問題 |
No.1646 Avoid Palindrome
|
ユーザー |
|
提出日時 | 2022-04-15 16:45:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 849 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 82,512 KB |
実行使用メモリ | 158,032 KB |
最終ジャッジ日時 | 2024-12-24 21:12:07 |
合計ジャッジ時間 | 124,826 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 TLE * 30 |
ソースコード
MOD = 998244353 def f(S): if S == "?": return -1 else: return ord(S) - 97 n = int(input()) S = input() if n == 1: if S == "?": print(26) else: print(1) exit() S = list(map(f, S)) dp = [0] * (26 * 26) if S[0] == -1: l1 = list(range(26)) else: l1 = [S[0]] if S[1] == -1: l2 = list(range(26)) else: l2 = [S[1]] for i in l1: for j in l2: if i != j: dp[i * 26 + j] = 1 for s in S[2:]: if s == -1: lst = list(range(26)) else: lst = [s] ndp = [0] * (26 * 26) for i in range(26): for j in range(26): for k in lst: if i == k or j == k: continue ndp[26 * j + k] += dp[26 * i + j] ndp[26 * j + k] %= MOD dp = ndp print(sum(dp) % MOD)