結果

問題 No.2396 等差二項展開
ユーザー ecotteaecottea
提出日時 2023-02-26 17:34:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 938 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 78,516 KB
最終ジャッジ日時 2024-04-16 04:40:12
合計ジャッジ時間 41,944 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 を取る箇所をミスる.これは WA してほしい.
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] % B
    
    for i in range(L):
        h[i] += h[i + L] * M % B
    
    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])
0