結果
問題 |
No.1646 Avoid Palindrome
|
ユーザー |
|
提出日時 | 2021-08-13 22:34:34 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 540 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 51,296 KB |
最終ジャッジ日時 | 2024-10-03 20:24:18 |
合計ジャッジ時間 | 36,547 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 TLE * 1 -- * 29 |
ソースコード
import numpy as np en2asc = lambda s: ord(s) - 97 N = int(input()) S = input() MOD = 998244353 dp = np.zeros((27, 27), dtype=np.int64) dp[-1, -1] = 1 for s in S: dp_sum = dp.sum(axis=1) new_dp = np.zeros((27, 27), dtype=np.int64) if s == '?': for i in range(26): tmp = dp_sum - dp[:, i] tmp[i] = 0 new_dp[i] += tmp else: i = en2asc(s) tmp = dp_sum - dp[:, i] tmp[i] = 0 new_dp[i] += tmp dp = new_dp % MOD ans = dp.sum() % MOD print(ans)