結果
問題 | No.1073 無限すごろく |
ユーザー | maspy |
提出日時 | 2020-06-05 22:37:09 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 594 ms / 2,000 ms |
コード長 | 1,366 bytes |
コンパイル時間 | 108 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 44,008 KB |
最終ジャッジ日時 | 2024-05-09 22:16:44 |
合計ジャッジ時間 | 21,533 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 555 ms
43,636 KB |
testcase_01 | AC | 552 ms
43,636 KB |
testcase_02 | AC | 548 ms
44,008 KB |
testcase_03 | AC | 565 ms
43,632 KB |
testcase_04 | AC | 560 ms
43,628 KB |
testcase_05 | AC | 539 ms
43,648 KB |
testcase_06 | AC | 548 ms
43,628 KB |
testcase_07 | AC | 561 ms
43,648 KB |
testcase_08 | AC | 561 ms
43,904 KB |
testcase_09 | AC | 549 ms
43,892 KB |
testcase_10 | AC | 553 ms
43,900 KB |
testcase_11 | AC | 560 ms
43,888 KB |
testcase_12 | AC | 564 ms
43,904 KB |
testcase_13 | AC | 576 ms
43,896 KB |
testcase_14 | AC | 577 ms
43,784 KB |
testcase_15 | AC | 586 ms
43,888 KB |
testcase_16 | AC | 594 ms
43,636 KB |
testcase_17 | AC | 580 ms
43,500 KB |
testcase_18 | AC | 579 ms
43,776 KB |
testcase_19 | AC | 580 ms
43,628 KB |
testcase_20 | AC | 583 ms
43,640 KB |
testcase_21 | AC | 562 ms
43,500 KB |
testcase_22 | AC | 523 ms
43,888 KB |
testcase_23 | AC | 539 ms
43,768 KB |
testcase_24 | AC | 539 ms
43,892 KB |
testcase_25 | AC | 553 ms
43,756 KB |
testcase_26 | AC | 544 ms
43,760 KB |
testcase_27 | AC | 542 ms
43,884 KB |
testcase_28 | AC | 544 ms
43,892 KB |
testcase_29 | AC | 545 ms
43,764 KB |
testcase_30 | AC | 548 ms
43,892 KB |
testcase_31 | AC | 539 ms
43,908 KB |
testcase_32 | AC | 540 ms
43,632 KB |
ソースコード
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 def convolve(f, g, MOD=MOD): Lf = len(f) Lg = len(g) fl = f & (1 << 15) - 1 fh = f >> 15 gl = g & (1 << 15) - 1 gh = g >> 15 def conv(f, g): return np.convolve(f, g) % MOD x = conv(fl, gl) y = conv(fl + fh, gl + gh) z = conv(fh, gh) a, b, c = map(lambda x: (x + .5).astype(np.int64), [x, y, z]) return (a + ((b - a - c) << 15) + (c << 30)) % MOD def coef_of_generating_function(P, Q, N): """compute the coefficient [x^N] P/Q of rational power series. Parameters ---------- P : np.ndarray numerator. Q : np.ndarray denominator Q[0] == 1 and len(Q) == len(P) + 1 is assumed. N : int The coefficient to compute. """ def conv(f, g): return convolve(f, g, MOD) while N: Q1 = Q.copy() Q1[1::2] = np.negative(Q1[1::2]) if N & 1: P = conv(P, Q1)[1::2] else: P = conv(P, Q1)[::2] Q = conv(Q, Q1)[::2] N >>= 1 return P[0] N = int(read()) t = -pow(6, MOD - 2, MOD) num = np.array([1, 0, 0, 0, 0, 0], np.int64) den = np.array([1, t, t, t, t, t, t], np.int64) print(coef_of_generating_function(num, den, N))