結果

問題 No.1646 Avoid Palindrome
ユーザー MitarushiMitarushi
提出日時 2021-07-29 12:51:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,289 ms / 3,000 ms
コード長 653 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 83,056 KB
最終ジャッジ日時 2024-04-26 02:26:40
合計ジャッジ時間 35,348 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
61,924 KB
testcase_01 AC 45 ms
62,276 KB
testcase_02 AC 42 ms
59,760 KB
testcase_03 AC 58 ms
67,968 KB
testcase_04 AC 878 ms
79,552 KB
testcase_05 AC 885 ms
80,388 KB
testcase_06 AC 853 ms
79,508 KB
testcase_07 AC 866 ms
79,708 KB
testcase_08 AC 939 ms
81,204 KB
testcase_09 AC 910 ms
80,380 KB
testcase_10 AC 892 ms
79,948 KB
testcase_11 AC 837 ms
79,724 KB
testcase_12 AC 850 ms
79,652 KB
testcase_13 AC 923 ms
81,656 KB
testcase_14 AC 1,175 ms
81,628 KB
testcase_15 AC 1,253 ms
82,936 KB
testcase_16 AC 1,164 ms
81,764 KB
testcase_17 AC 1,221 ms
82,284 KB
testcase_18 AC 1,249 ms
81,896 KB
testcase_19 AC 1,177 ms
83,056 KB
testcase_20 AC 1,214 ms
82,676 KB
testcase_21 AC 1,232 ms
82,144 KB
testcase_22 AC 1,183 ms
82,228 KB
testcase_23 AC 1,159 ms
82,116 KB
testcase_24 AC 1,274 ms
82,896 KB
testcase_25 AC 1,258 ms
82,520 KB
testcase_26 AC 1,246 ms
82,544 KB
testcase_27 AC 1,289 ms
82,920 KB
testcase_28 AC 1,261 ms
82,144 KB
testcase_29 AC 747 ms
79,468 KB
testcase_30 AC 921 ms
79,960 KB
testcase_31 AC 748 ms
79,204 KB
testcase_32 AC 715 ms
78,908 KB
testcase_33 AC 739 ms
79,468 KB
testcase_34 AC 1,125 ms
80,724 KB
testcase_35 AC 34 ms
52,944 KB
testcase_36 AC 37 ms
58,724 KB
testcase_37 AC 43 ms
60,364 KB
testcase_38 AC 41 ms
58,912 KB
testcase_39 AC 39 ms
59,260 KB
testcase_40 AC 38 ms
59,512 KB
testcase_41 AC 40 ms
59,924 KB
testcase_42 AC 39 ms
60,576 KB
testcase_43 AC 755 ms
79,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()

mod = 998244353
dp = [[0] * 27 for _ in range(27)]
dp[-1][-1] = 1

for i in s:
    

    if i == "?":
        i_sum = [sum(dp[j][i] for j in range(27)) for i in range(27)]
        dp2 = [[0 if i == j or j == 26 else i_sum[i] - dp[j][i] for j in range(27)]for i in range(27)]

    else:
        char = ord(i) - ord("a")
        
        dp2 = [[0] * 27 for _ in range(27)]
        for i in range(27):
            for j in range(27):
                if i == char or j == char:
                    continue
                dp2[j][char] += dp[i][j]

    dp = [[i % mod for i in j] for j in dp2]

print(sum(map(sum, dp)) % mod)
0