結果

問題 No.1646 Avoid Palindrome
ユーザー puznekopuzneko
提出日時 2021-10-24 23:23:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,195 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 467,348 KB
最終ジャッジ日時 2024-04-10 04:32:01
合計ジャッジ時間 59,894 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
61,416 KB
testcase_01 AC 47 ms
61,924 KB
testcase_02 AC 46 ms
59,940 KB
testcase_03 AC 54 ms
64,032 KB
testcase_04 AC 1,854 ms
444,100 KB
testcase_05 AC 1,781 ms
443,564 KB
testcase_06 AC 1,611 ms
431,000 KB
testcase_07 AC 1,791 ms
443,976 KB
testcase_08 AC 1,805 ms
447,828 KB
testcase_09 AC 1,606 ms
429,148 KB
testcase_10 AC 1,631 ms
438,068 KB
testcase_11 AC 1,595 ms
427,508 KB
testcase_12 AC 1,781 ms
443,384 KB
testcase_13 AC 1,795 ms
447,656 KB
testcase_14 AC 1,667 ms
437,084 KB
testcase_15 AC 1,849 ms
444,448 KB
testcase_16 AC 1,657 ms
434,548 KB
testcase_17 AC 1,868 ms
450,980 KB
testcase_18 AC 1,678 ms
440,012 KB
testcase_19 AC 1,672 ms
438,828 KB
testcase_20 AC 1,682 ms
440,988 KB
testcase_21 AC 1,864 ms
450,712 KB
testcase_22 AC 1,664 ms
437,548 KB
testcase_23 AC 1,873 ms
452,744 KB
testcase_24 AC 1,957 ms
466,680 KB
testcase_25 AC 1,948 ms
466,968 KB
testcase_26 AC 1,942 ms
466,712 KB
testcase_27 AC 1,948 ms
467,348 KB
testcase_28 AC 1,936 ms
466,888 KB
testcase_29 AC 1,840 ms
466,772 KB
testcase_30 AC 1,958 ms
466,608 KB
testcase_31 AC 1,844 ms
466,548 KB
testcase_32 AC 1,844 ms
466,732 KB
testcase_33 AC 1,826 ms
466,456 KB
testcase_34 AC 1,914 ms
465,812 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 41 ms
59,364 KB
testcase_38 AC 41 ms
59,564 KB
testcase_39 AC 41 ms
57,940 KB
testcase_40 AC 41 ms
57,768 KB
testcase_41 AC 41 ms
59,332 KB
testcase_42 AC 42 ms
58,948 KB
testcase_43 AC 1,892 ms
466,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()
p = 998244353
alptonum = {"?":0,"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,"t":20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":26}

if n == 1:
    if s[i] == "?":
        print("{}".format(26))
    else:
        print("{}".format(1))
    exit()

dp = [[[0 for k in range(27)] for i in range(27)] for j in range(n+1)]
if s[0] == "?":
    for i in range(1,27):
        dp[1][0][i] = 1
else:
    dp[1][0][alptonum[s[0]]] = 1

for i in range(1,n):
    if s[i] == "?":
        for j in range(1,27):
            karisum = 0
            for k in range(27):
                karisum = (karisum + dp[i][k][j]) % p
            for k in range(1,27):
                if j != k:
                    dp[i+1][j][k] = (karisum - dp[i][k][j]) % p
    else:
        ind = alptonum[s[i]]
        for j in range(1,27):
            if j != ind:
                for k in range(27):
                    if k != ind:
                        dp[i+1][j][ind] = (dp[i+1][j][ind] + dp[i][k][j]) % p

ans = 0
for i in range(1,27):
    for j in range(1,27):
        ans = (ans + dp[n][i][j]) % p

print("{}".format(ans))

0