結果

問題 No.1646 Avoid Palindrome
ユーザー tktk_snsntktk_snsn
提出日時 2021-08-13 23:18:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 699 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,504 KB
実行使用メモリ 435,036 KB
最終ジャッジ日時 2024-04-14 20:31:02
合計ジャッジ時間 38,588 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
67,424 KB
testcase_01 AC 40 ms
52,496 KB
testcase_02 AC 37 ms
53,532 KB
testcase_03 AC 73 ms
76,588 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def rng(s):
    if s == "?":
        for i in range(26):
            yield i
    else:
        yield ord(s) - 97


N = int(input())
S = input()
dp = [[[0]*26 for _ in range(26)] for _ in range(N)]
for i in rng(S[0]):
    for j in rng(S[1]):
        if i == j:
            continue
        dp[1][i][j] = 1

for i in range(2, N):
    for x in rng(S[i]):
        for y in rng(S[i-1]):
            if x != y:
                for z in rng(S[i-2]):
                    if x != z:
                        dp[i][y][x] += dp[i-1][z][y]
                        dp[i][y][x] %= mod

ans = 0
for i in range(26):
    for j in range(26):
        ans += dp[N-1][i][j]
        ans %= mod
print(ans)
0