結果

問題 No.1646 Avoid Palindrome
ユーザー titiatitia
提出日時 2021-08-14 00:46:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,101 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 78,860 KB
最終ジャッジ日時 2024-04-14 22:15:48
合計ジャッジ時間 34,957 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
61,108 KB
testcase_01 AC 46 ms
61,908 KB
testcase_02 AC 46 ms
61,556 KB
testcase_03 AC 53 ms
64,036 KB
testcase_04 AC 1,138 ms
78,184 KB
testcase_05 AC 1,137 ms
78,064 KB
testcase_06 AC 1,102 ms
78,668 KB
testcase_07 AC 1,144 ms
78,004 KB
testcase_08 AC 957 ms
78,060 KB
testcase_09 AC 1,093 ms
77,632 KB
testcase_10 AC 1,125 ms
78,256 KB
testcase_11 AC 1,042 ms
78,508 KB
testcase_12 AC 1,160 ms
78,228 KB
testcase_13 AC 1,148 ms
77,668 KB
testcase_14 AC 877 ms
78,708 KB
testcase_15 AC 909 ms
78,860 KB
testcase_16 AC 891 ms
78,704 KB
testcase_17 AC 908 ms
78,412 KB
testcase_18 AC 883 ms
78,500 KB
testcase_19 AC 879 ms
78,532 KB
testcase_20 AC 890 ms
78,532 KB
testcase_21 AC 911 ms
78,856 KB
testcase_22 AC 880 ms
78,272 KB
testcase_23 AC 906 ms
78,172 KB
testcase_24 AC 942 ms
78,560 KB
testcase_25 AC 942 ms
78,764 KB
testcase_26 AC 940 ms
78,560 KB
testcase_27 AC 944 ms
78,560 KB
testcase_28 AC 944 ms
78,524 KB
testcase_29 AC 1,122 ms
78,576 KB
testcase_30 AC 1,094 ms
78,380 KB
testcase_31 AC 1,102 ms
78,500 KB
testcase_32 AC 1,106 ms
78,640 KB
testcase_33 AC 1,119 ms
78,532 KB
testcase_34 AC 1,224 ms
78,660 KB
testcase_35 AC 37 ms
52,616 KB
testcase_36 WA -
testcase_37 AC 37 ms
52,616 KB
testcase_38 AC 38 ms
53,840 KB
testcase_39 AC 40 ms
52,332 KB
testcase_40 AC 39 ms
53,548 KB
testcase_41 AC 39 ms
52,736 KB
testcase_42 AC 40 ms
53,364 KB
testcase_43 AC 1,128 ms
78,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod=998244353

N=int(input())
S=list(input().strip())

for i in range(N):
    S[i]=ord(S[i])-97

if N==1:
    print(1)
    exit()

DP=[0]*(26*26)

for i in range(26):
    for j in range(26):
        if i==j:
            continue

        if (i==S[0] or -34==S[0]) and (j==S[1] or -34==S[1]):
            DP[i*26+j]=1

#print(DP)

for stind in range(2,N):
    NDP1=[0]*(26*26)
    NDP2=[0]*(26*26)

    x=S[stind]

    for i in range(26):
        for j in range(26):
            kake=DP[i*26+j]

            if x==-34:
                NDP1[j*26]+=kake
                NDP1[j*26+i]-=kake
                if i!=25:
                    NDP1[j*26+i+1]+=kake
                NDP1[j*26+j]-=kake
                if j!=25:
                    NDP1[j*26+j+1]+=kake
                
            else:
                if i!=x and j!=x:
                    NDP2[j*26+x]+=kake

    for i in range(26):
        for j in range(1,26):
            NDP1[i*26+j]+=NDP1[i*26+j-1]

    DP=[0]*(26*26)

    for i in range(26*26):
        DP[i]=(NDP1[i]+NDP2[i])%mod

print(sum(DP)%mod)
0