結果

問題 No.129 お年玉(2)
ユーザー maspymaspy
提出日時 2020-02-24 20:30:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 519 ms / 5,000 ms
コード長 1,264 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 44,624 KB
最終ジャッジ日時 2024-04-20 15:23:28
合計ジャッジ時間 27,204 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 496 ms
43,984 KB
testcase_01 AC 500 ms
43,980 KB
testcase_02 AC 492 ms
43,984 KB
testcase_03 AC 489 ms
43,988 KB
testcase_04 AC 495 ms
44,372 KB
testcase_05 AC 499 ms
43,856 KB
testcase_06 AC 497 ms
44,372 KB
testcase_07 AC 501 ms
43,860 KB
testcase_08 AC 501 ms
44,240 KB
testcase_09 AC 501 ms
44,248 KB
testcase_10 AC 495 ms
44,256 KB
testcase_11 AC 503 ms
44,116 KB
testcase_12 AC 506 ms
44,364 KB
testcase_13 AC 503 ms
44,624 KB
testcase_14 AC 504 ms
43,984 KB
testcase_15 AC 503 ms
44,364 KB
testcase_16 AC 509 ms
43,860 KB
testcase_17 AC 513 ms
44,368 KB
testcase_18 AC 500 ms
43,984 KB
testcase_19 AC 509 ms
43,984 KB
testcase_20 AC 493 ms
44,368 KB
testcase_21 AC 503 ms
44,364 KB
testcase_22 AC 505 ms
44,368 KB
testcase_23 AC 513 ms
44,252 KB
testcase_24 AC 496 ms
43,852 KB
testcase_25 AC 505 ms
44,380 KB
testcase_26 AC 500 ms
43,992 KB
testcase_27 AC 503 ms
43,984 KB
testcase_28 AC 500 ms
44,252 KB
testcase_29 AC 498 ms
43,796 KB
testcase_30 AC 491 ms
44,368 KB
testcase_31 AC 501 ms
43,980 KB
testcase_32 AC 503 ms
43,736 KB
testcase_33 AC 503 ms
44,364 KB
testcase_34 AC 497 ms
43,980 KB
testcase_35 AC 499 ms
44,368 KB
testcase_36 AC 494 ms
44,236 KB
testcase_37 AC 494 ms
43,856 KB
testcase_38 AC 498 ms
43,856 KB
testcase_39 AC 497 ms
44,492 KB
testcase_40 AC 495 ms
44,364 KB
testcase_41 AC 492 ms
43,856 KB
testcase_42 AC 499 ms
43,856 KB
testcase_43 AC 492 ms
44,364 KB
testcase_44 AC 503 ms
44,240 KB
testcase_45 AC 502 ms
44,244 KB
testcase_46 AC 496 ms
44,248 KB
testcase_47 AC 509 ms
44,244 KB
testcase_48 AC 519 ms
44,380 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