結果

問題 No.3182 recurrence relation’s intersection sum
ユーザー ooaiu
提出日時 2025-07-27 23:13:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 514 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 39,552 KB
最終ジャッジ日時 2025-07-27 23:13:15
合計ジャッジ時間 6,643 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other -- * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
mod=998244353
K,L,R=map(int,input().split())
s=object
A=np.zeros((K+4,K+4),dtype=s)
for i in range(K+1):
    A[i,0]=A[i,i]=1
    for j in range(1,i):A[i,j]=(A[i-1,j-1]+A[i-1,j])%mod
B=np.zeros(K+4,dtype=s)
A[K+1,K+1]=A[K+2,K+2]=A[K+3,K+1]=K;A[K+1,K]=A[K+1,K+2]=A[K+3,K+3]=A[K+3,K]=A[K+3,K+2]=B[0]=B[K+1]=B[K+2]=B[K+3]=1
def p(a,n):
    r=np.eye(K+4,dtype=s)
    while n:
        if n&1:r=(r@a)%mod
        a=(a@a)%mod;n>>=1
    return r
ans=p(A,R)
if L-1>=0:ans-=p(A,L-1)
print((ans[K+3]@B)%mod)
0