結果
問題 | No.802 だいたい等差数列 |
ユーザー |
![]() |
提出日時 | 2020-03-24 02:50:49 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,536 ms / 2,000 ms |
コード長 | 1,240 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 164,848 KB |
最終ジャッジ日時 | 2024-12-30 06:47:24 |
合計ジャッジ時間 | 29,554 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#!/usr/bin/ python3.8import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesimport numpy as npMOD = 10 ** 9 + 7def cumprod(A, MOD=MOD):L = len(A)Lsq = int(L**.5 + 1)A = np.resize(A, Lsq**2).reshape(Lsq, Lsq)for n in range(1, Lsq):A[:, n] *= A[:, n - 1]A[:, n] %= MODfor n in range(1, Lsq):A[n] *= A[n - 1, -1]A[n] %= MODreturn A.ravel()[:L]def make_fact(U, MOD=MOD):x = np.arange(U, dtype=np.int64)x[0] = 1fact = cumprod(x, MOD)x = np.arange(U, 0, -1, dtype=np.int64)x[0] = pow(int(fact[-1]), MOD - 2, MOD)fact_inv = cumprod(x, MOD)[::-1]fact.flags.writeable = Falsefact_inv.flags.writeable = Falsereturn fact, fact_invN, M, D1, D2 = map(int, read().split())M -= 1 + D1 * (N - 1)if M < 0:print(0)exit()n = D2 - D1 + 1fact, fact_inv = make_fact(N + M + 10)fact = fact.tolist()fact_inv = fact_inv.tolist()answer = 0for i in range(N):j = M - n * iif j < 0:breakx = fact[N - 1] * fact_inv[i] * fact_inv[N - 1 - i]y = fact[N + j] * fact_inv[N] * fact_inv[j]answer += x * y * pow(-1, i)print(answer % MOD)