結果

問題 No.1646 Avoid Palindrome
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-20 15:48:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,920 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 80,208 KB
最終ジャッジ日時 2023-08-15 13:26:33
合計ジャッジ時間 51,170 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,436 KB
testcase_01 AC 94 ms
77,196 KB
testcase_02 AC 90 ms
77,156 KB
testcase_03 AC 102 ms
77,296 KB
testcase_04 AC 1,103 ms
79,680 KB
testcase_05 WA -
testcase_06 AC 1,230 ms
79,748 KB
testcase_07 AC 1,107 ms
79,452 KB
testcase_08 WA -
testcase_09 AC 1,083 ms
79,448 KB
testcase_10 AC 1,199 ms
80,096 KB
testcase_11 AC 1,081 ms
79,604 KB
testcase_12 AC 1,115 ms
79,852 KB
testcase_13 WA -
testcase_14 AC 1,884 ms
79,840 KB
testcase_15 AC 1,919 ms
79,876 KB
testcase_16 AC 1,898 ms
79,664 KB
testcase_17 AC 1,957 ms
79,796 KB
testcase_18 AC 1,878 ms
79,760 KB
testcase_19 AC 1,852 ms
79,672 KB
testcase_20 AC 1,882 ms
79,560 KB
testcase_21 AC 1,908 ms
79,652 KB
testcase_22 AC 1,871 ms
79,764 KB
testcase_23 AC 1,930 ms
79,876 KB
testcase_24 AC 2,003 ms
79,748 KB
testcase_25 AC 2,036 ms
80,036 KB
testcase_26 AC 2,074 ms
79,568 KB
testcase_27 AC 2,109 ms
79,756 KB
testcase_28 AC 2,084 ms
79,888 KB
testcase_29 AC 854 ms
79,320 KB
testcase_30 AC 832 ms
79,396 KB
testcase_31 AC 838 ms
80,208 KB
testcase_32 AC 826 ms
79,584 KB
testcase_33 AC 785 ms
79,416 KB
testcase_34 AC 2,122 ms
78,812 KB
testcase_35 AC 86 ms
71,536 KB
testcase_36 AC 87 ms
71,448 KB
testcase_37 AC 89 ms
71,724 KB
testcase_38 AC 85 ms
71,644 KB
testcase_39 WA -
testcase_40 AC 88 ms
71,664 KB
testcase_41 AC 90 ms
71,436 KB
testcase_42 AC 85 ms
71,712 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = sys.stdin.readline

from collections import Counter

mod = 998244353

def main():

    n = int(input())
    s = str(input().rstrip())

    if n == 1:
        if s[0] == '?':
            print(26)
        else:
            print(1)
        exit()

    dp = [0]*(26*26)
    if s[0] != '?' and s[1] != '?':
        c0 = ord(s[0])-ord('a')
        c1 = ord(s[0])-ord('a')
        dp[c1*26+c0] = 1
    elif s[0] != '?':
        c0 = ord(s[0])-ord('a')
        for c1 in range(26):
            if c0 == c1:
                continue
            dp[c1*26+c0] = 1
    elif s[1] != '?':
        c1 = ord(s[1])-ord('a')
        for c0 in range(26):
            if c0 == c1:
                continue
            dp[c1*26+c0] = 1
    else:
        for c0 in range(26):
            for c1 in range(26):
                if c0 == c1:
                    continue
                dp[c1*26+c0] = 1

    for i in range(2, n):
        nx = [0]*(26*26)
        c = s[i]
        if c == '?':
            d1 = Counter()
            for c0 in range(26):
                for c1 in range(26):
                    d1[c1] += dp[c1*26+c0]
                    d1[c1] %= mod
            for c in range(26):
                for c1 in range(26):
                    if c == c1:
                        continue
                    nx[c*26+c1] += d1[c1]-dp[c1*26+c]
                    nx[c*26+c1] %= mod
        else:
            c = ord(c)-ord('a')
            for c0 in range(26):
                if c0 == c:
                    continue
                for c1 in range(26):
                    if c1 == c:
                        continue
                    nx[c*26+c1] += dp[c1*26+c0]
                    nx[c*26+c1] %= mod
        dp = nx
    ans = 0
    for c0 in range(26):
        for c1 in range(26):
            ans += dp[c1*26+c0]
            ans %= mod
    print(ans)

if __name__ == '__main__':
    main()
0