結果

問題 No.2396 等差二項展開
ユーザー ecotteaecottea
提出日時 2023-02-26 17:31:22
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 947 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 80,256 KB
最終ジャッジ日時 2024-04-16 04:38:19
合計ジャッジ時間 9,102 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
62,720 KB
testcase_01 AC 66 ms
62,976 KB
testcase_02 AC 64 ms
62,976 KB
testcase_03 AC 63 ms
62,848 KB
testcase_04 AC 63 ms
63,104 KB
testcase_05 AC 63 ms
63,232 KB
testcase_06 AC 62 ms
63,104 KB
testcase_07 AC 63 ms
63,232 KB
testcase_08 AC 63 ms
62,976 KB
testcase_09 AC 63 ms
63,232 KB
testcase_10 AC 63 ms
63,104 KB
testcase_11 AC 63 ms
63,360 KB
testcase_12 AC 63 ms
63,104 KB
testcase_13 AC 129 ms
77,952 KB
testcase_14 AC 292 ms
80,256 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import re
import sys

content = input()
pattern = r'^(\d+) (\d+) (\d+) (\d+) (\d+)$'
result = re.match(pattern, content)

if not result:
    sys.exit("format error.")

N, M, L, K, B = map(int, result.groups())

if not (1 <= N and N <= 10**18):
    sys.exit("N")

if not (1 <= M and M <= 10**18):
    sys.exit("M")

if not (1 <= L and L <= 10**3):
    sys.exit("L")

if not (0 <= K and K < L):
    sys.exit("K")

if not (1 <= B and B <= 10**9):
    sys.exit("B")


if L == 1:
   print(pow(M + 1, N, B))
   exit()

# 途中で mod を取らずに計算.これは TLE か MLE してほしい.
def mul(f, g):
    h = [0] * (2 * L)
    for i in range(L):
        for j in range(L):
            h[i + j] += f[i] * g[j]
    
    for i in range(L):
        h[i] += h[i + L] * M
    
    return h

f = [0] * L
f[0] = 1

p = [0] * L
p[0] = 1
p[1] = 1

while N > 0:
    if N % 2 == 1:
        f = mul(f, p)
    p = mul(p, p)
    N //= 2

print(f[K] % B)
0