結果

問題 No.1646 Avoid Palindrome
ユーザー puznekopuzneko
提出日時 2021-10-24 23:29:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,809 ms / 3,000 ms
コード長 1,195 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 466,944 KB
最終ジャッジ日時 2024-04-10 04:42:56
合計ジャッジ時間 54,760 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
60,676 KB
testcase_01 AC 43 ms
62,100 KB
testcase_02 AC 45 ms
59,868 KB
testcase_03 AC 48 ms
63,380 KB
testcase_04 AC 1,644 ms
444,180 KB
testcase_05 AC 1,607 ms
443,492 KB
testcase_06 AC 1,418 ms
431,012 KB
testcase_07 AC 1,638 ms
443,772 KB
testcase_08 AC 1,650 ms
447,844 KB
testcase_09 AC 1,472 ms
429,016 KB
testcase_10 AC 1,496 ms
437,672 KB
testcase_11 AC 1,441 ms
427,160 KB
testcase_12 AC 1,649 ms
443,444 KB
testcase_13 AC 1,627 ms
447,892 KB
testcase_14 AC 1,523 ms
436,784 KB
testcase_15 AC 1,672 ms
444,516 KB
testcase_16 AC 1,520 ms
434,468 KB
testcase_17 AC 1,704 ms
450,648 KB
testcase_18 AC 1,513 ms
440,512 KB
testcase_19 AC 1,504 ms
438,504 KB
testcase_20 AC 1,570 ms
441,012 KB
testcase_21 AC 1,704 ms
450,680 KB
testcase_22 AC 1,579 ms
437,256 KB
testcase_23 AC 1,762 ms
452,164 KB
testcase_24 AC 1,776 ms
466,684 KB
testcase_25 AC 1,732 ms
466,788 KB
testcase_26 AC 1,792 ms
466,720 KB
testcase_27 AC 1,788 ms
466,676 KB
testcase_28 AC 1,809 ms
466,776 KB
testcase_29 AC 1,683 ms
466,944 KB
testcase_30 AC 1,753 ms
466,740 KB
testcase_31 AC 1,670 ms
466,428 KB
testcase_32 AC 1,689 ms
466,376 KB
testcase_33 AC 1,710 ms
466,504 KB
testcase_34 AC 1,735 ms
466,268 KB
testcase_35 AC 34 ms
52,696 KB
testcase_36 AC 32 ms
52,812 KB
testcase_37 AC 36 ms
58,120 KB
testcase_38 AC 38 ms
58,360 KB
testcase_39 AC 38 ms
59,256 KB
testcase_40 AC 36 ms
58,112 KB
testcase_41 AC 38 ms
58,708 KB
testcase_42 AC 38 ms
59,476 KB
testcase_43 AC 1,689 ms
466,624 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[0] == "?":
        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