結果

問題 No.1646 Avoid Palindrome
ユーザー wolgnikwolgnik
提出日時 2021-08-13 21:54:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,947 ms / 3,000 ms
コード長 1,346 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 84,944 KB
最終ジャッジ日時 2023-08-08 09:30:17
合計ジャッジ時間 53,001 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,080 KB
testcase_01 AC 87 ms
76,376 KB
testcase_02 AC 83 ms
76,384 KB
testcase_03 AC 89 ms
76,664 KB
testcase_04 AC 1,388 ms
84,004 KB
testcase_05 AC 1,396 ms
83,340 KB
testcase_06 AC 1,423 ms
83,016 KB
testcase_07 AC 1,388 ms
83,360 KB
testcase_08 AC 1,402 ms
83,408 KB
testcase_09 AC 1,458 ms
83,208 KB
testcase_10 AC 1,456 ms
83,484 KB
testcase_11 AC 1,418 ms
82,756 KB
testcase_12 AC 1,479 ms
83,824 KB
testcase_13 AC 1,392 ms
83,712 KB
testcase_14 AC 1,657 ms
83,292 KB
testcase_15 AC 1,696 ms
83,504 KB
testcase_16 AC 1,655 ms
83,124 KB
testcase_17 AC 1,713 ms
83,520 KB
testcase_18 AC 1,665 ms
83,260 KB
testcase_19 AC 1,659 ms
83,136 KB
testcase_20 AC 1,688 ms
83,348 KB
testcase_21 AC 1,718 ms
83,536 KB
testcase_22 AC 1,658 ms
82,996 KB
testcase_23 AC 1,721 ms
83,360 KB
testcase_24 AC 1,774 ms
83,804 KB
testcase_25 AC 1,782 ms
83,864 KB
testcase_26 AC 1,784 ms
83,772 KB
testcase_27 AC 1,789 ms
83,872 KB
testcase_28 AC 1,772 ms
83,688 KB
testcase_29 AC 1,287 ms
83,680 KB
testcase_30 AC 1,258 ms
83,768 KB
testcase_31 AC 1,457 ms
84,944 KB
testcase_32 AC 1,292 ms
83,728 KB
testcase_33 AC 1,270 ms
83,768 KB
testcase_34 AC 1,947 ms
83,168 KB
testcase_35 AC 74 ms
71,240 KB
testcase_36 AC 73 ms
71,392 KB
testcase_37 AC 75 ms
71,440 KB
testcase_38 AC 75 ms
71,080 KB
testcase_39 AC 75 ms
71,256 KB
testcase_40 AC 77 ms
71,232 KB
testcase_41 AC 76 ms
71,256 KB
testcase_42 AC 77 ms
71,432 KB
testcase_43 AC 1,222 ms
83,812 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