結果
| 問題 | No.1646 Avoid Palindrome |
| コンテスト | |
| ユーザー |
sotanishy
|
| 提出日時 | 2021-08-14 22:52:14 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 824 bytes |
| 記録 | |
| コンパイル時間 | 72 ms |
| コンパイル使用メモリ | 80,640 KB |
| 実行使用メモリ | 83,712 KB |
| 最終ジャッジ日時 | 2026-09-10 20:58:16 |
| 合計ジャッジ時間 | 107,892 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 24 TLE * 16 |
ソースコード
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