結果

問題 No.1646 Avoid Palindrome
ユーザー titiatitia
提出日時 2021-08-14 00:48:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,215 ms / 3,000 ms
コード長 1,151 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 79,304 KB
最終ジャッジ日時 2024-04-26 03:39:23
合計ジャッジ時間 35,430 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
61,568 KB
testcase_01 AC 47 ms
61,568 KB
testcase_02 AC 43 ms
61,312 KB
testcase_03 AC 54 ms
63,872 KB
testcase_04 AC 1,143 ms
77,824 KB
testcase_05 AC 1,140 ms
78,080 KB
testcase_06 AC 1,095 ms
78,336 KB
testcase_07 AC 1,140 ms
77,840 KB
testcase_08 AC 961 ms
78,416 KB
testcase_09 AC 1,086 ms
78,080 KB
testcase_10 AC 1,121 ms
78,568 KB
testcase_11 AC 1,051 ms
78,444 KB
testcase_12 AC 1,163 ms
77,952 KB
testcase_13 AC 1,148 ms
77,952 KB
testcase_14 AC 877 ms
78,712 KB
testcase_15 AC 911 ms
78,664 KB
testcase_16 AC 908 ms
78,720 KB
testcase_17 AC 911 ms
78,692 KB
testcase_18 AC 891 ms
78,464 KB
testcase_19 AC 887 ms
78,776 KB
testcase_20 AC 897 ms
78,592 KB
testcase_21 AC 924 ms
78,700 KB
testcase_22 AC 885 ms
78,592 KB
testcase_23 AC 911 ms
78,384 KB
testcase_24 AC 945 ms
78,720 KB
testcase_25 AC 943 ms
78,720 KB
testcase_26 AC 935 ms
78,856 KB
testcase_27 AC 946 ms
79,304 KB
testcase_28 AC 943 ms
78,720 KB
testcase_29 AC 1,127 ms
78,720 KB
testcase_30 AC 1,097 ms
78,632 KB
testcase_31 AC 1,102 ms
78,568 KB
testcase_32 AC 1,108 ms
79,052 KB
testcase_33 AC 1,118 ms
78,680 KB
testcase_34 AC 1,215 ms
78,372 KB
testcase_35 AC 37 ms
52,608 KB
testcase_36 AC 36 ms
52,352 KB
testcase_37 AC 38 ms
52,480 KB
testcase_38 AC 38 ms
52,352 KB
testcase_39 AC 38 ms
52,608 KB
testcase_40 AC 38 ms
52,352 KB
testcase_41 AC 38 ms
53,120 KB
testcase_42 AC 39 ms
52,992 KB
testcase_43 AC 1,119 ms
79,060 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:
    if S[0]!=-34:
        print(1)
    else:
        print(26)
    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