結果

問題 No.1646 Avoid Palindrome
ユーザー H3PO4H3PO4
提出日時 2021-08-13 22:34:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 540 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 51,412 KB
最終ジャッジ日時 2024-04-14 18:57:14
合計ジャッジ時間 37,903 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 512 ms
51,412 KB
testcase_01 AC 508 ms
44,088 KB
testcase_02 AC 510 ms
44,600 KB
testcase_03 AC 506 ms
43,960 KB
testcase_04 AC 2,755 ms
44,336 KB
testcase_05 AC 2,773 ms
44,352 KB
testcase_06 AC 2,677 ms
44,084 KB
testcase_07 AC 2,764 ms
44,348 KB
testcase_08 AC 2,755 ms
44,216 KB
testcase_09 AC 2,628 ms
44,092 KB
testcase_10 AC 2,709 ms
44,344 KB
testcase_11 AC 2,642 ms
44,340 KB
testcase_12 AC 2,743 ms
44,084 KB
testcase_13 AC 2,771 ms
44,344 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0