結果
問題 |
No.2396 等差二項展開
|
ユーザー |
|
提出日時 | 2023-02-26 17:31:22 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 947 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 81,944 KB |
実行使用メモリ | 267,540 KB |
最終ジャッジ日時 | 2024-10-06 16:30:05 |
合計ジャッジ時間 | 8,929 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 TLE * 1 -- * 15 |
ソースコード
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)