結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー maspy
提出日時 2019-12-03 10:07:10
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,141 ms / 5,000 ms
コード長 1,708 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 222,488 KB
最終ジャッジ日時 2024-11-28 11:15:07
合計ジャッジ時間 18,110 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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 = 2 * (X + Y + Z + 100)
fact,fact_inv = make_fact(U,MOD)
power2 = make_power(2,U,MOD)
power2_inv = make_power((1+MOD)//2,U,MOD)

# P = 1/2(1-x)(1-y)(1-z)
# (2P-1)^nを足しまくる
# 1-(2P-1)^N / (2-2P), NはX+Y+Zより十分大きければなんでも

N = X + Y + Z + 1
if not N&1:
    N += 1
A = fact[N] * fact_inv[:N+1] % MOD * fact_inv[:N+1][::-1] % MOD
A *= power2[:N+1]; A %= MOD
A[1::2] *= (-1)
A[0] += 1
# 2-2x で割る
A *= (MOD+1)//2; A %= MOD
np.cumsum(A,out=A); A %= MOD
# 1/(1-x)(1-y)(1-z)になおして
A *= power2_inv[:N+1]; A %= MOD
for x in [X,Y,Z]:
    # (1/1-T)^n でX次
    B = np.zeros(N+1,np.int64)
    if x == 0:
        B[0] = 1
    B[1:] = fact[x:x+N] * fact_inv[x] % MOD * fact_inv[:N] % MOD
    A *= B; A %= MOD

answer = A.sum() % MOD
print(answer)
0