結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 KazunKazun
提出日時 2021-08-13 22:24:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 777 ms / 3,000 ms
コード長 1,504 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 81,820 KB
最終ジャッジ日時 2024-04-26 03:09:32
合計ジャッジ時間 23,232 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
69,216 KB
testcase_01 AC 61 ms
69,180 KB
testcase_02 AC 54 ms
65,408 KB
testcase_03 AC 68 ms
73,288 KB
testcase_04 AC 664 ms
81,152 KB
testcase_05 AC 581 ms
80,932 KB
testcase_06 AC 558 ms
80,520 KB
testcase_07 AC 579 ms
81,360 KB
testcase_08 AC 569 ms
81,064 KB
testcase_09 AC 561 ms
80,700 KB
testcase_10 AC 572 ms
81,044 KB
testcase_11 AC 550 ms
80,712 KB
testcase_12 AC 571 ms
81,044 KB
testcase_13 AC 587 ms
81,112 KB
testcase_14 AC 721 ms
80,660 KB
testcase_15 AC 733 ms
80,620 KB
testcase_16 AC 731 ms
80,184 KB
testcase_17 AC 748 ms
80,596 KB
testcase_18 AC 741 ms
80,708 KB
testcase_19 AC 729 ms
80,664 KB
testcase_20 AC 724 ms
80,552 KB
testcase_21 AC 736 ms
80,832 KB
testcase_22 AC 721 ms
80,796 KB
testcase_23 AC 774 ms
81,200 KB
testcase_24 AC 770 ms
80,624 KB
testcase_25 AC 759 ms
80,832 KB
testcase_26 AC 772 ms
80,824 KB
testcase_27 AC 764 ms
80,832 KB
testcase_28 AC 777 ms
80,492 KB
testcase_29 AC 492 ms
81,696 KB
testcase_30 AC 494 ms
81,636 KB
testcase_31 AC 491 ms
81,780 KB
testcase_32 AC 487 ms
81,544 KB
testcase_33 AC 501 ms
81,520 KB
testcase_34 AC 757 ms
80,800 KB
testcase_35 AC 54 ms
65,480 KB
testcase_36 AC 54 ms
65,944 KB
testcase_37 AC 54 ms
64,328 KB
testcase_38 AC 53 ms
64,840 KB
testcase_39 AC 55 ms
64,412 KB
testcase_40 AC 56 ms
64,272 KB
testcase_41 AC 57 ms
65,528 KB
testcase_42 AC 55 ms
64,700 KB
testcase_43 AC 502 ms
81,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from string import ascii_lowercase as X
from collections import defaultdict
N=int(input())
S=["*"]
for s in input():
    if s=="?":
        S.append(-1)
    else:
        S.append(ord(s)-ord("a"))
Mod=998244353

#==================================================
def answer(x):
    exit(print(x))

def f(a,b):
    return 26*a+b

#==================================================
if N==1:
    if S[1]==-1:
        answer(26)
    else:
        answer(1)

for i in range(1,N):
    if S[i]==S[i+1] and S[i]!=-1:
        answer(0)

for i in range(1,N-1):
    if S[i]==S[i+2] and S[i]!=-1:
        answer(0)

D=[0]*676
R=range(26)
if S[1]==-1:
    if S[2]==-1:
        for a in R:
            for b in R:
                if a!=b:
                    D[f(a,b)]=1
    else:
        for a in R:
            if a!=S[2]:
                D[f(a,S[2])]=1
else:
    if S[2]==-1:
        for b in R:
            if S[1]!=b:
                D[f(S[1],b)]=1
    else:
        D[f(S[1],S[2])]=1

for c in S[3:]:
    E=D
    D=[0]*676

    if c==-1:
        L=[0]*26
        M=[0]*676

        for i in range(676):
            a,b=divmod(i,26)
            L[b]+=E[f(a,b)]
            M[f(b,a)]+=E[f(a,b)]
            M[f(b,b)]+=E[f(a,b)]

        for a in R:
            for b in R:
                D[f(a,b)]=L[a]-M[f(a,b)]
    else:
        for i in range(676):
            a,b=divmod(i,26)
            if a!=c and b!=c:
                D[f(b,c)]+=E[f(a,b)]

    for i in range(676):
        D[i]%=Mod

print(sum(D)%Mod)
0