結果

問題 No.2396 等差二項展開
ユーザー とりゐとりゐ
提出日時 2023-07-28 22:24:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,003 ms / 6,000 ms
コード長 422 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 73,216 KB
最終ジャッジ日時 2024-04-16 06:22:17
合計ジャッジ時間 10,086 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,968 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 41 ms
51,840 KB
testcase_03 AC 40 ms
51,968 KB
testcase_04 AC 49 ms
59,520 KB
testcase_05 AC 42 ms
52,480 KB
testcase_06 AC 41 ms
51,968 KB
testcase_07 AC 49 ms
59,776 KB
testcase_08 AC 53 ms
60,800 KB
testcase_09 AC 41 ms
51,584 KB
testcase_10 AC 42 ms
52,096 KB
testcase_11 AC 41 ms
51,712 KB
testcase_12 AC 41 ms
51,712 KB
testcase_13 AC 57 ms
62,336 KB
testcase_14 AC 58 ms
62,208 KB
testcase_15 AC 78 ms
65,536 KB
testcase_16 AC 205 ms
68,480 KB
testcase_17 AC 611 ms
71,424 KB
testcase_18 AC 859 ms
73,216 KB
testcase_19 AC 1,003 ms
72,704 KB
testcase_20 AC 42 ms
52,096 KB
testcase_21 AC 42 ms
52,224 KB
testcase_22 AC 41 ms
51,840 KB
testcase_23 AC 461 ms
69,760 KB
testcase_24 AC 709 ms
71,424 KB
testcase_25 AC 854 ms
73,088 KB
testcase_26 AC 640 ms
70,784 KB
testcase_27 AC 707 ms
71,680 KB
testcase_28 AC 776 ms
72,320 KB
testcase_29 AC 706 ms
71,808 KB
testcase_30 AC 526 ms
70,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(a,b):
  c=[0]*L
  for i in range(L):
    for j in range(L):
      if i+j>=L:
        c[(i+j)%L]+=a[i]*b[j]%mod*M
      else:
        c[(i+j)]+=a[i]*b[j]%mod
      c[(i+j)%L]%=mod
  return c

N,M,L,K,mod=map(int,input().split())
M%=mod
if L==1:
  print(pow(M+1,N,mod))
  exit()

ans=[0]*L
ans[0]=1
tmp=[0]*L
tmp[0]=1
tmp[1]+=1

for i in range(60):
  if (N>>i)&1:
    ans=f(ans,tmp)
  tmp=f(tmp,tmp)

print(ans[K]%mod)
0