結果

問題 No.1646 Avoid Palindrome
ユーザー convexineqconvexineq
提出日時 2021-08-13 23:40:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,068 ms / 3,000 ms
コード長 977 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 78,456 KB
最終ジャッジ日時 2024-04-26 03:39:49
合計ジャッジ時間 24,901 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,424 KB
testcase_01 AC 43 ms
62,080 KB
testcase_02 AC 43 ms
61,096 KB
testcase_03 AC 47 ms
63,384 KB
testcase_04 AC 590 ms
77,628 KB
testcase_05 AC 582 ms
77,868 KB
testcase_06 AC 741 ms
77,780 KB
testcase_07 AC 587 ms
77,708 KB
testcase_08 AC 615 ms
77,868 KB
testcase_09 AC 694 ms
77,400 KB
testcase_10 AC 743 ms
77,672 KB
testcase_11 AC 692 ms
77,548 KB
testcase_12 AC 722 ms
77,528 KB
testcase_13 AC 591 ms
77,712 KB
testcase_14 AC 747 ms
77,836 KB
testcase_15 AC 766 ms
77,708 KB
testcase_16 AC 748 ms
77,612 KB
testcase_17 AC 772 ms
77,648 KB
testcase_18 AC 738 ms
77,672 KB
testcase_19 AC 738 ms
77,656 KB
testcase_20 AC 743 ms
77,652 KB
testcase_21 AC 768 ms
77,680 KB
testcase_22 AC 734 ms
77,652 KB
testcase_23 AC 745 ms
77,728 KB
testcase_24 AC 783 ms
78,456 KB
testcase_25 AC 787 ms
77,964 KB
testcase_26 AC 787 ms
77,948 KB
testcase_27 AC 796 ms
77,820 KB
testcase_28 AC 785 ms
78,308 KB
testcase_29 AC 531 ms
78,144 KB
testcase_30 AC 533 ms
77,832 KB
testcase_31 AC 681 ms
77,748 KB
testcase_32 AC 580 ms
77,772 KB
testcase_33 AC 516 ms
78,056 KB
testcase_34 AC 1,068 ms
77,316 KB
testcase_35 AC 37 ms
53,080 KB
testcase_36 AC 37 ms
53,552 KB
testcase_37 AC 38 ms
53,140 KB
testcase_38 AC 38 ms
53,268 KB
testcase_39 AC 38 ms
53,824 KB
testcase_40 AC 38 ms
54,136 KB
testcase_41 AC 39 ms
53,816 KB
testcase_42 AC 37 ms
53,468 KB
testcase_43 AC 512 ms
77,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
n = int(input())
s = [ord(i)-97 for i in input()]
if len(s)==1:
    print(26 if s[0] < 0 else 1)
    exit()
M = 26
dp = [[0]*M for _ in range(M)]
for i in range(M):
    for j in range(M):
        if i != j and (s[0] == i or s[0] < 0) and (s[1] == j or s[1] < 0):
            dp[i][j] += 1

for v in s[2:]:
    ndp = [[0]*M for _ in range(M)]
    if v < 0:
        c = [0]*M
        for i in range(M):
            for j in range(M):
                if i==j: continue
                c[j] += dp[i][j]
                ndp[j][i] -= dp[i][j]
        for i in range(M):
            for j in range(M):
                if i==j: continue
                ndp[i][j] += c[i]
                ndp[i][j] %= MOD
    else:
        for i in range(M):
            if i == v: continue
            for j in range(M):
                if j == v: continue
                ndp[j][v] += dp[i][j]
                ndp[j][v] %= MOD
    dp = ndp        

print(sum(sum(di) for di in dp)%MOD)
0