結果

問題 No.1761 Sequence Distance
ユーザー NyaanNyaan
提出日時 2021-10-24 22:43:45
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 678 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 523,392 KB
最終ジャッジ日時 2025-01-03 13:14:42
合計ジャッジ時間 127,205 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 1
other AC * 34 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
from copy import deepcopy

mod = 998244353
N, M = map(int, input().split())
sq = int(sqrt(2 * M) + 3)

init = [[0] * (M + 1) for _ in range(sq)]
dp = deepcopy(init)
dp[0][0] = 1

for _ in range(N):
  nx = deepcopy(init)
  for i in range(sq):
    for j in range(M + 1):
      if dp[i][j] == 0:
        continue
      im1 = abs(i - 1)
      if j + im1 <= M:
        nx[im1][j + im1] += dp[i][j]
        nx[im1][j + im1] %= mod
      if j + i <= M:
        nx[i][j + i] += dp[i][j] * 2
        nx[i][j + i] %= mod
      if i != sq - 1 and j + i + 1 <= M:
        nx[i + 1][j + i + 1] += dp[i][j]
        nx[i + 1][j + i + 1] %= mod
  dp = nx

print(dp[0][M])
0