結果

問題 No.1646 Avoid Palindrome
ユーザー wolgnikwolgnik
提出日時 2021-08-13 21:54:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,873 ms / 3,000 ms
コード長 1,346 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 83,988 KB
最終ジャッジ日時 2024-04-26 02:48:06
合計ジャッジ時間 49,056 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,168 KB
testcase_01 AC 46 ms
62,776 KB
testcase_02 AC 45 ms
60,956 KB
testcase_03 AC 51 ms
65,840 KB
testcase_04 AC 1,213 ms
82,508 KB
testcase_05 AC 1,271 ms
82,564 KB
testcase_06 AC 1,374 ms
82,572 KB
testcase_07 AC 1,287 ms
82,412 KB
testcase_08 AC 1,310 ms
82,552 KB
testcase_09 AC 1,352 ms
82,080 KB
testcase_10 AC 1,342 ms
82,936 KB
testcase_11 AC 1,322 ms
82,136 KB
testcase_12 AC 1,381 ms
82,408 KB
testcase_13 AC 1,251 ms
82,648 KB
testcase_14 AC 1,534 ms
82,332 KB
testcase_15 AC 1,583 ms
82,452 KB
testcase_16 AC 1,554 ms
82,320 KB
testcase_17 AC 1,609 ms
82,524 KB
testcase_18 AC 1,576 ms
82,648 KB
testcase_19 AC 1,541 ms
82,304 KB
testcase_20 AC 1,602 ms
82,456 KB
testcase_21 AC 1,661 ms
82,828 KB
testcase_22 AC 1,574 ms
82,328 KB
testcase_23 AC 1,624 ms
82,724 KB
testcase_24 AC 1,702 ms
82,944 KB
testcase_25 AC 1,708 ms
83,064 KB
testcase_26 AC 1,677 ms
83,012 KB
testcase_27 AC 1,674 ms
83,076 KB
testcase_28 AC 1,682 ms
82,932 KB
testcase_29 AC 1,146 ms
83,112 KB
testcase_30 AC 1,097 ms
83,196 KB
testcase_31 AC 1,211 ms
83,988 KB
testcase_32 AC 1,091 ms
82,928 KB
testcase_33 AC 1,127 ms
83,196 KB
testcase_34 AC 1,873 ms
82,676 KB
testcase_35 AC 37 ms
53,864 KB
testcase_36 AC 37 ms
53,140 KB
testcase_37 AC 39 ms
53,136 KB
testcase_38 AC 38 ms
52,816 KB
testcase_39 AC 38 ms
52,748 KB
testcase_40 AC 38 ms
54,120 KB
testcase_41 AC 40 ms
54,384 KB
testcase_42 AC 38 ms
53,628 KB
testcase_43 AC 1,111 ms
83,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
S = list(input())[: -1]
mod = 998244353

dp = [[0] * 26 for _ in range(26)]

if N == 1:
  if S[0] == "?": print(26)
  else: print(1)
  exit(0)

for x in range(26):
  for y in range(26):
    if x == y: continue
    cx = chr(ord("a") + x)
    cy = chr(ord("a") + y)

    if S[0] == cx and S[1] == cy: dp[x][y] += 1
    if S[0] == "?" and S[1] == cy: dp[x][y] += 1
    if S[0] == cx and S[1] == "?": dp[x][y] += 1
    if S[0] == "?" and S[1] == "?": dp[x][y] += 1
#print(dp)
for c in S[2: ]:
  z = ord(c) - ord("a")
  dp2 = [[0] * 26 for _ in range(26)]
  if c != "?":
    for x in range(26):
      for y in range(26):
        cx = chr(ord("a") + x)
        cy = chr(ord("a") + y)
        if x != z and y != z:
          dp2[y][z] += dp[x][y]
          dp2[y][z] %= mod
  else:
    sm = [0] * 26
    for x in range(26):
      for y in range(26):
        cx = chr(ord("a") + x)
        cy = chr(ord("a") + y)
        dp2[y][y] -= dp[x][y]
        dp2[y][y] %= mod
        dp2[y][x] -= dp[x][y]
        dp2[y][y] %= mod

        sm[y] += dp[x][y]
        sm[y] %= mod

    for x in range(26):
      for y in range(26):
        dp2[x][y] += sm[x]
        dp2[x][y] %= mod

  dp = [t[: ] for t in dp2]

res = 0
for x in range(26):
  for y in range(26):
    res += dp[x][y]
    res %= mod
print(res)
0