結果

問題 No.1646 Avoid Palindrome
ユーザー mkawa2mkawa2
提出日時 2021-08-13 22:19:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,928 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,620 KB
実行使用メモリ 83,476 KB
最終ジャッジ日時 2024-04-14 18:31:08
合計ジャッジ時間 16,103 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
62,412 KB
testcase_01 AC 41 ms
59,964 KB
testcase_02 AC 39 ms
53,356 KB
testcase_03 AC 58 ms
68,276 KB
testcase_04 AC 1,191 ms
76,496 KB
testcase_05 AC 1,179 ms
76,260 KB
testcase_06 AC 916 ms
76,340 KB
testcase_07 AC 1,193 ms
76,388 KB
testcase_08 AC 953 ms
76,400 KB
testcase_09 AC 881 ms
76,204 KB
testcase_10 AC 895 ms
76,440 KB
testcase_11 AC 1,125 ms
76,748 KB
testcase_12 AC 1,211 ms
76,188 KB
testcase_13 AC 1,170 ms
76,672 KB
testcase_14 TLE -
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 #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = 10**16
md = 998244353
# md = 10**9+7

n = II()
s = SI()

if n == 1:
    if s[0] == "?":
        print(26)
    else:
        print(1)
    exit()

for i in range(n-1):
    if s[i] != "?" and s[i] == s[i+1]:
        print(0)
        exit()

for i in range(n-2):
    if s[i] != "?" and s[i] == s[i+2]:
        print(0)
        exit()

dp = [0]*26*26

if s[0] == "?" and s[1] == "?":
    for i in range(26):
        for j in range(26):
            if i == j: continue
            dp[i*26+j] = 1
elif s[0] == "?":
    j = ord(s[1])-97
    for i in range(26):
        if i == j: continue
        dp[i*26+j] = 1
elif s[1] == "?":
    i = ord(s[0])-97
    for j in range(26):
        if i == j: continue
        dp[i*26+j] = 1
else:
    i = ord(s[0])-97
    j = ord(s[1])-97
    dp[i*26+j] = 1

def add(i, j, val):
    ndp[i*26+j] = (ndp[i*26+j]+val)%md

for c in s[2:]:
    a = ord(c)-97
    ndp = [0]*26*26
    for i in range(26):
        for j in range(26):
            pre = dp[i*26+j]
            if pre == 0: continue
            if c == "?":
                for nj in range(26):
                    if nj == i or nj == j: continue
                    add(j, nj, pre)
            elif a != i and a != j:
                add(j, a, pre)
    dp = ndp

ans = 0
for i in range(26):
    for j in range(26):
        ans += dp[i*26+j]
    ans %= md

print(ans)
0