結果

問題 No.129 お年玉(2)
ユーザー maspymaspy
提出日時 2020-02-24 20:30:12
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 1,264 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 30,916 KB
最終ジャッジ日時 2023-08-02 15:18:53
合計ジャッジ時間 9,274 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
29,940 KB
testcase_01 AC 139 ms
30,748 KB
testcase_02 AC 133 ms
29,744 KB
testcase_03 AC 132 ms
29,712 KB
testcase_04 AC 130 ms
29,792 KB
testcase_05 AC 137 ms
30,152 KB
testcase_06 AC 139 ms
30,168 KB
testcase_07 AC 139 ms
30,568 KB
testcase_08 AC 137 ms
30,340 KB
testcase_09 AC 142 ms
30,648 KB
testcase_10 AC 141 ms
30,568 KB
testcase_11 AC 136 ms
30,288 KB
testcase_12 AC 138 ms
30,692 KB
testcase_13 AC 140 ms
30,540 KB
testcase_14 AC 138 ms
30,508 KB
testcase_15 AC 139 ms
30,044 KB
testcase_16 AC 135 ms
30,140 KB
testcase_17 AC 143 ms
30,720 KB
testcase_18 AC 138 ms
30,576 KB
testcase_19 AC 140 ms
30,596 KB
testcase_20 AC 140 ms
30,696 KB
testcase_21 AC 138 ms
30,760 KB
testcase_22 AC 132 ms
30,172 KB
testcase_23 AC 140 ms
30,916 KB
testcase_24 AC 138 ms
30,852 KB
testcase_25 AC 135 ms
30,116 KB
testcase_26 AC 133 ms
30,136 KB
testcase_27 AC 135 ms
30,200 KB
testcase_28 AC 138 ms
30,584 KB
testcase_29 AC 129 ms
29,612 KB
testcase_30 AC 127 ms
29,788 KB
testcase_31 AC 128 ms
29,788 KB
testcase_32 AC 128 ms
29,824 KB
testcase_33 AC 129 ms
29,720 KB
testcase_34 AC 130 ms
29,788 KB
testcase_35 AC 130 ms
29,860 KB
testcase_36 AC 134 ms
29,696 KB
testcase_37 AC 136 ms
29,828 KB
testcase_38 AC 133 ms
29,908 KB
testcase_39 AC 133 ms
30,016 KB
testcase_40 AC 137 ms
30,168 KB
testcase_41 AC 136 ms
30,324 KB
testcase_42 AC 136 ms
30,100 KB
testcase_43 AC 137 ms
30,088 KB
testcase_44 AC 141 ms
30,760 KB
testcase_45 AC 134 ms
30,080 KB
testcase_46 AC 133 ms
30,144 KB
testcase_47 AC 137 ms
30,728 KB
testcase_48 AC 135 ms
30,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
import numpy as np


# %%
N, M = map(int, read().split())
N, M

# %%
MOD = 10 ** 9


# %%
def fft_convolve(f, g, MOD=MOD):
    """
    数列 (多項式) f, g の畳み込みの計算.上下 15 bitずつ分けて計算することで,
    30 bit以下の整数,長さ 250000 程度の数列での計算が正確に行える.
    """
    fft = np.fft.rfft
    ifft = np.fft.irfft
    Lf = len(f)
    Lg = len(g)
    L = Lf + Lg - 1
    fft_len = 1 << L.bit_length()
    fl = f & (1 << 15) - 1
    fh = f >> 15
    gl = g & (1 << 15) - 1
    gh = g >> 15

    def conv(f, g):
        return ifft(fft(f, fft_len) * fft(g, fft_len))[:L]
    x = conv(fl, gl) % MOD
    y = conv(fl + fh, gl + gh) % MOD
    z = conv(fh, gh) % MOD
    a, b, c = map(lambda x: (x + .5).astype(np.int64), [x, y, z])
    return (a + ((b - a - c) << 15) + (c << 30)) % MOD


# %%
def make_comb(n):
    if n == 0:
        return np.int64([1])
    P = make_comb(n // 2)
    P = fft_convolve(P, P)
    if n & 1:
        P = np.convolve(P, np.int64([1, 1])) % MOD
    return P


# %%
answer = make_comb(M)[(N // 1000) % M]
print(answer)
0