結果

問題 No.1646 Avoid Palindrome
ユーザー roarisroaris
提出日時 2021-08-20 19:40:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 685 ms / 3,000 ms
コード長 961 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,348 KB
最終ジャッジ日時 2024-04-26 03:55:19
合計ジャッジ時間 20,648 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
61,796 KB
testcase_01 AC 47 ms
63,708 KB
testcase_02 AC 45 ms
62,908 KB
testcase_03 AC 52 ms
65,084 KB
testcase_04 AC 521 ms
76,964 KB
testcase_05 AC 520 ms
76,928 KB
testcase_06 AC 505 ms
76,912 KB
testcase_07 AC 518 ms
77,056 KB
testcase_08 AC 516 ms
77,064 KB
testcase_09 AC 495 ms
77,184 KB
testcase_10 AC 512 ms
77,112 KB
testcase_11 AC 502 ms
76,928 KB
testcase_12 AC 522 ms
76,928 KB
testcase_13 AC 541 ms
77,184 KB
testcase_14 AC 643 ms
76,928 KB
testcase_15 AC 661 ms
77,328 KB
testcase_16 AC 636 ms
77,056 KB
testcase_17 AC 662 ms
76,940 KB
testcase_18 AC 647 ms
77,068 KB
testcase_19 AC 636 ms
76,944 KB
testcase_20 AC 644 ms
76,960 KB
testcase_21 AC 649 ms
77,036 KB
testcase_22 AC 632 ms
76,928 KB
testcase_23 AC 660 ms
77,232 KB
testcase_24 AC 685 ms
77,312 KB
testcase_25 AC 677 ms
76,928 KB
testcase_26 AC 675 ms
77,056 KB
testcase_27 AC 670 ms
76,928 KB
testcase_28 AC 675 ms
77,312 KB
testcase_29 AC 450 ms
77,136 KB
testcase_30 AC 449 ms
76,928 KB
testcase_31 AC 449 ms
76,928 KB
testcase_32 AC 446 ms
76,972 KB
testcase_33 AC 450 ms
76,972 KB
testcase_34 AC 673 ms
77,184 KB
testcase_35 AC 40 ms
54,016 KB
testcase_36 AC 40 ms
54,400 KB
testcase_37 AC 41 ms
54,144 KB
testcase_38 AC 42 ms
54,016 KB
testcase_39 AC 40 ms
54,528 KB
testcase_40 AC 41 ms
54,016 KB
testcase_41 AC 42 ms
54,272 KB
testcase_42 AC 42 ms
54,144 KB
testcase_43 AC 477 ms
77,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N = int(input())
S = input()[:-1]

if N==1:
    if S=='?':
        print(26)
    else:
        print(1)
    exit()
    
dp = [[0]*26 for _ in range(26)]
MOD = 998244353

for i in range(26):
    for j in range(26):
        if i!=j and (S[1]=='?' or ord(S[1])-ord('a')==i) and (S[0]=='?' or ord(S[0])-ord('a')==j):
            dp[i][j] = 1

for i in range(2, N):
    sus = []
    
    for j in range(26):
        su = 0
        
        for k in range(26):
            su += dp[j][k]
            su %= MOD
        
        sus.append(su)
        
    ndp = [[0]*26 for _ in range(26)]
    
    for j in range(26):
        if S[i]=='?' or ord(S[i])-ord('a')==j:
            for k in range(26):
                if j!=k:
                    ndp[j][k] = (sus[k]-dp[k][j])%MOD
    
    dp = ndp

ans = 0

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

print(ans)
0