結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 tamatotamato
提出日時 2021-08-13 21:47:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 632 ms / 3,000 ms
コード長 1,042 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 78,044 KB
最終ジャッジ日時 2024-04-26 02:42:00
合計ジャッジ時間 19,105 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
60,728 KB
testcase_01 AC 43 ms
61,388 KB
testcase_02 AC 40 ms
58,900 KB
testcase_03 AC 44 ms
61,592 KB
testcase_04 AC 490 ms
77,632 KB
testcase_05 AC 489 ms
77,128 KB
testcase_06 AC 480 ms
77,508 KB
testcase_07 AC 495 ms
77,780 KB
testcase_08 AC 490 ms
77,668 KB
testcase_09 AC 470 ms
77,396 KB
testcase_10 AC 493 ms
77,480 KB
testcase_11 AC 632 ms
77,652 KB
testcase_12 AC 475 ms
77,548 KB
testcase_13 AC 492 ms
77,640 KB
testcase_14 AC 515 ms
77,704 KB
testcase_15 AC 535 ms
77,460 KB
testcase_16 AC 529 ms
77,324 KB
testcase_17 AC 560 ms
77,340 KB
testcase_18 AC 540 ms
77,480 KB
testcase_19 AC 529 ms
77,276 KB
testcase_20 AC 531 ms
77,340 KB
testcase_21 AC 548 ms
77,440 KB
testcase_22 AC 529 ms
77,796 KB
testcase_23 AC 546 ms
77,648 KB
testcase_24 AC 567 ms
77,608 KB
testcase_25 AC 561 ms
77,720 KB
testcase_26 AC 572 ms
77,736 KB
testcase_27 AC 556 ms
77,748 KB
testcase_28 AC 572 ms
77,976 KB
testcase_29 AC 473 ms
77,612 KB
testcase_30 AC 460 ms
77,680 KB
testcase_31 AC 466 ms
78,032 KB
testcase_32 AC 468 ms
77,884 KB
testcase_33 AC 465 ms
77,172 KB
testcase_34 AC 561 ms
76,736 KB
testcase_35 AC 37 ms
53,464 KB
testcase_36 AC 37 ms
54,060 KB
testcase_37 AC 40 ms
58,980 KB
testcase_38 AC 37 ms
52,908 KB
testcase_39 AC 41 ms
59,076 KB
testcase_40 AC 41 ms
58,472 KB
testcase_41 AC 41 ms
58,892 KB
testcase_42 AC 41 ms
58,672 KB
testcase_43 AC 495 ms
78,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')

    dp = [[0] * 27 for _ in range(27)]
    dp[0][0] = 1
    for i, s in enumerate(S):
        dp_new = [[0] * 27 for _ in range(27)]
        if s == "?":
            sum_j2 = [0] * 27
            for j1 in range(27):
                for j2 in range(27):
                    sum_j2[j2] = (sum_j2[j2] + dp[j1][j2])%mod
            for j2 in range(27):
                for j in range(1, 27):
                    if j2 != j:
                        dp_new[j2][j] = (sum_j2[j2] - dp[j][j2])%mod
        else:
            j = ord(s) - 96
            for j2 in range(27):
                for j1 in range(27):
                    if j1 != j and j2 != j:
                        dp_new[j2][j] = (dp_new[j2][j] + dp[j1][j2])%mod
        dp = dp_new
    ans = 0
    for j1 in range(27):
        for j2 in range(27):
            ans = (ans + dp[j1][j2])%mod
    print(ans)


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