結果
| 問題 |
No.2396 等差二項展開
|
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2023-07-28 23:06:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,104 ms / 6,000 ms |
| コード長 | 856 bytes |
| コンパイル時間 | 293 ms |
| コンパイル使用メモリ | 81,908 KB |
| 実行使用メモリ | 76,324 KB |
| 最終ジャッジ日時 | 2024-10-06 21:03:50 |
| 合計ジャッジ時間 | 11,754 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
N, M, L, K, B = map(int, input().split())
if L == 1:
print(pow(1 + M, N, B))
exit()
now = [0] * L
now[0] = now[1] = 1
lst = []
while N != 1:
if N % 2 == 0:
lst.append(1)
N //= 2
else:
lst.append(0)
N -= 1
lst.reverse()
for flag in lst:
if flag:
nex = [0] * (2 * L)
for i in range(L):
for j in range(L):
nex[i + j] += now[i] * now[j]
nex[i + j] %= B
for i in range(L, 2 * L):
nex[i - L] += nex[i] * M
nex[i - L - 1] %= B
else:
nex = [0] * (L + 1)
for i in range(L):
nex[i] += now[i]
nex[i + 1] += now[i]
nex[i] %= B
nex[i + 1] %= B
nex[0] += nex[L] * M
nex[0] %= B
now = nex[:L]
print(now[K])
rlangevin