結果

問題 No.1646 Avoid Palindrome
ユーザー wolgnikwolgnik
提出日時 2021-08-13 21:52:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,346 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 83,912 KB
最終ジャッジ日時 2024-04-14 17:42:15
合計ジャッジ時間 50,585 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,720 KB
testcase_01 AC 47 ms
61,872 KB
testcase_02 AC 49 ms
61,792 KB
testcase_03 AC 51 ms
65,892 KB
testcase_04 AC 1,337 ms
82,724 KB
testcase_05 AC 1,347 ms
82,568 KB
testcase_06 AC 1,390 ms
82,160 KB
testcase_07 AC 1,353 ms
82,244 KB
testcase_08 AC 1,354 ms
82,304 KB
testcase_09 AC 1,394 ms
82,120 KB
testcase_10 AC 1,418 ms
82,828 KB
testcase_11 AC 1,369 ms
81,956 KB
testcase_12 AC 1,451 ms
82,464 KB
testcase_13 AC 1,357 ms
82,576 KB
testcase_14 AC 1,617 ms
82,820 KB
testcase_15 AC 1,652 ms
82,564 KB
testcase_16 AC 1,622 ms
82,276 KB
testcase_17 AC 1,686 ms
82,788 KB
testcase_18 AC 1,628 ms
82,444 KB
testcase_19 AC 1,618 ms
82,864 KB
testcase_20 AC 1,639 ms
82,268 KB
testcase_21 AC 1,684 ms
82,940 KB
testcase_22 AC 1,626 ms
82,380 KB
testcase_23 AC 1,710 ms
82,976 KB
testcase_24 AC 1,729 ms
82,780 KB
testcase_25 AC 1,746 ms
82,724 KB
testcase_26 AC 1,740 ms
82,980 KB
testcase_27 AC 1,750 ms
82,664 KB
testcase_28 AC 1,746 ms
83,004 KB
testcase_29 AC 1,233 ms
82,860 KB
testcase_30 AC 1,225 ms
82,664 KB
testcase_31 AC 1,419 ms
83,912 KB
testcase_32 AC 1,239 ms
82,928 KB
testcase_33 AC 1,215 ms
82,988 KB
testcase_34 AC 1,914 ms
82,616 KB
testcase_35 WA -
testcase_36 AC 37 ms
52,272 KB
testcase_37 AC 39 ms
53,208 KB
testcase_38 AC 38 ms
53,292 KB
testcase_39 AC 38 ms
52,684 KB
testcase_40 AC 39 ms
52,528 KB
testcase_41 AC 38 ms
53,436 KB
testcase_42 AC 39 ms
54,368 KB
testcase_43 AC 1,235 ms
83,244 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(0)
  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