結果
問題 |
No.2396 等差二項展開
|
ユーザー |
|
提出日時 | 2023-02-26 17:34:31 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 938 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 82,208 KB |
実行使用メモリ | 78,472 KB |
最終ジャッジ日時 | 2024-10-06 16:32:26 |
合計ジャッジ時間 | 41,352 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 16 TLE * 1 |
ソースコード
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])