結果

問題 No.3391 Line up Dominoes
コンテスト
ユーザー timi
提出日時 2025-11-29 00:40:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,820 ms / 3,000 ms
コード長 573 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 82,292 KB
実行使用メモリ 77,480 KB
最終ジャッジ日時 2025-11-29 00:40:44
合計ジャッジ時間 40,260 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N,M,K=map(int, input().split())
A=list(map(int, input().split()))
A=sorted(A)
mod=998244353
import bisect
B=[]
for a in A:
  l=bisect.bisect_left(A,a-K)
  r=bisect.bisect_left(A,a+K+1)
  B.append((l,r))
  
dp0=[1]*N
dp1=[0]*N 
C=[0]*(N+1)
for i in range(M-1):
  for j in range(N):
    if i%2==0:
      C[j+1]=C[j]+dp0[j]
    else:
      C[j+1]=C[j]+dp1[j]

  if i%2==0:
    for j in range(N):
      l,r=B[j]
      dp1[j]=(C[r]-C[l])%mod
  else:
    for j in range(N):
      l,r=B[j]
      dp0[j]=(C[r]-C[l])%mod

if M%2==0:
  print(sum(dp1)%mod)
else:
  print(sum(dp0)%mod)
0