結果
問題 |
No.1646 Avoid Palindrome
|
ユーザー |
![]() |
提出日時 | 2021-08-13 23:40:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,070 ms / 3,000 ms |
コード長 | 977 bytes |
コンパイル時間 | 361 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 78,080 KB |
最終ジャッジ日時 | 2024-11-08 16:09:01 |
合計ジャッジ時間 | 25,410 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
MOD = 998244353 n = int(input()) s = [ord(i)-97 for i in input()] if len(s)==1: print(26 if s[0] < 0 else 1) exit() M = 26 dp = [[0]*M for _ in range(M)] for i in range(M): for j in range(M): if i != j and (s[0] == i or s[0] < 0) and (s[1] == j or s[1] < 0): dp[i][j] += 1 for v in s[2:]: ndp = [[0]*M for _ in range(M)] if v < 0: c = [0]*M for i in range(M): for j in range(M): if i==j: continue c[j] += dp[i][j] ndp[j][i] -= dp[i][j] for i in range(M): for j in range(M): if i==j: continue ndp[i][j] += c[i] ndp[i][j] %= MOD else: for i in range(M): if i == v: continue for j in range(M): if j == v: continue ndp[j][v] += dp[i][j] ndp[j][v] %= MOD dp = ndp print(sum(sum(di) for di in dp)%MOD)