結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー maspymaspy
提出日時 2019-12-04 10:47:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 2,778 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 11,188 KB
実行使用メモリ 99,892 KB
最終ジャッジ日時 2023-08-20 01:50:17
合計ジャッジ時間 7,610 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 133 ms
29,704 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

X,Y,Z = map(int,read().split())

MOD = 10 ** 9 + 7

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = 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]
    return fact,fact_inv

def make_power(a,L,MOD):
    B = L.bit_length()
    x = np.empty(1 + (1<<B),np.int64)
    x[0] = 1; x[1] = a
    for n in range(B):
        x[1<<n:1<<(n+1)] = x[:1<<n] * (a * x[(1<<n)-1] % MOD) % MOD
    return x[:L]

U = X + Y + Z + 100
fact,fact_inv = make_fact(U,MOD)
power2 = make_power(2,U,MOD)

def fft_convolve(f,g,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
    conv = lambda f,g: 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 f(X,Y,Z):
    if X==Y==Z==0:
        return 1
    """
    (2-2P/1-2P)^{Z+1} * (1/4-4P) の x^Xy^Y の係数を返す
    """
    N = Z + 1
    U = X + Y + 100
    # 分子
    A = fact[N] * fact_inv[:N+1] % MOD * fact_inv[:N+1][::-1]
    A[1::2] *= (-1); A %= MOD
    A = A[:U]; A *= power2[N]; A %= MOD
    # 分母の逆
    B = fact[N-1:N+U-1] * fact_inv[N-1] % MOD * fact_inv[:U] % MOD
    B *= power2[:U]; B %= MOD
    C = fft_convolve(A,B)[:U]
    # 4 - 4P で割る
    C *= (MOD+1)//4; C %= MOD; np.cumsum(C,out=C); C %= MOD
    # 各 n に対して、P^n = (x + y - xy)^n での x^Xy^Y の係数を求める
    L = max(X,Y); R = X+Y
    x = np.zeros(R-L+1,np.int64)
    x = fact[L:R+1].copy()
    x *= fact_inv[L-Y:R-Y+1]; x %= MOD
    x *= fact_inv[L-X:R-X+1]; x %= MOD
    x *= fact_inv[0:X+Y-L+1][::-1]; x %= MOD
    x[(R+L+1)%2::2] *= (-1)
    return (x * C[L:R+1] % MOD).sum() % MOD

# 3, 13, 512, 882313923
# f(1,1,0), f(1,1,1), f(10,0,0), f(31,53,6000), f(53,31,6000)
# f(6000,31,53), f(6000,53,31)

answer = f(X,Y,Z)
print(answer)
0