結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 KazunKazun
提出日時 2021-08-13 22:24:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 876 ms / 3,000 ms
コード長 1,504 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 86,372 KB
最終ジャッジ日時 2023-08-08 09:56:05
合計ジャッジ時間 28,157 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
80,796 KB
testcase_01 AC 160 ms
80,988 KB
testcase_02 AC 152 ms
79,964 KB
testcase_03 AC 163 ms
80,908 KB
testcase_04 AC 781 ms
86,212 KB
testcase_05 AC 680 ms
85,884 KB
testcase_06 AC 661 ms
85,332 KB
testcase_07 AC 671 ms
85,868 KB
testcase_08 AC 693 ms
85,640 KB
testcase_09 AC 655 ms
85,280 KB
testcase_10 AC 670 ms
85,928 KB
testcase_11 AC 649 ms
84,824 KB
testcase_12 AC 673 ms
85,624 KB
testcase_13 AC 681 ms
85,916 KB
testcase_14 AC 818 ms
85,480 KB
testcase_15 AC 817 ms
85,568 KB
testcase_16 AC 803 ms
84,968 KB
testcase_17 AC 829 ms
85,604 KB
testcase_18 AC 821 ms
85,172 KB
testcase_19 AC 822 ms
85,592 KB
testcase_20 AC 812 ms
85,376 KB
testcase_21 AC 833 ms
85,492 KB
testcase_22 AC 805 ms
85,228 KB
testcase_23 AC 876 ms
85,660 KB
testcase_24 AC 860 ms
85,188 KB
testcase_25 AC 867 ms
85,508 KB
testcase_26 AC 875 ms
85,496 KB
testcase_27 AC 866 ms
85,368 KB
testcase_28 AC 856 ms
85,364 KB
testcase_29 AC 581 ms
86,012 KB
testcase_30 AC 600 ms
86,128 KB
testcase_31 AC 596 ms
86,136 KB
testcase_32 AC 582 ms
86,360 KB
testcase_33 AC 584 ms
86,372 KB
testcase_34 AC 868 ms
85,260 KB
testcase_35 AC 148 ms
79,892 KB
testcase_36 AC 149 ms
80,016 KB
testcase_37 AC 150 ms
80,020 KB
testcase_38 AC 149 ms
79,924 KB
testcase_39 AC 150 ms
79,684 KB
testcase_40 AC 148 ms
79,928 KB
testcase_41 AC 149 ms
80,152 KB
testcase_42 AC 152 ms
79,916 KB
testcase_43 AC 582 ms
86,248 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