結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー vwxyzvwxyz
提出日時 2023-04-05 14:55:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 5,741 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 859,368 KB
最終ジャッジ日時 2024-10-02 01:07:53
合計ジャッジ時間 18,049 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
89,472 KB
testcase_01 AC 161 ms
89,088 KB
testcase_02 AC 155 ms
89,088 KB
testcase_03 AC 257 ms
102,244 KB
testcase_04 AC 164 ms
89,088 KB
testcase_05 AC 234 ms
94,824 KB
testcase_06 AC 218 ms
92,804 KB
testcase_07 AC 220 ms
92,424 KB
testcase_08 AC 196 ms
92,160 KB
testcase_09 AC 217 ms
92,604 KB
testcase_10 AC 209 ms
92,536 KB
testcase_11 AC 189 ms
91,776 KB
testcase_12 AC 220 ms
94,868 KB
testcase_13 AC 209 ms
92,984 KB
testcase_14 AC 179 ms
91,008 KB
testcase_15 AC 1,875 ms
320,016 KB
testcase_16 TLE -
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write

def Extended_Euclid(n,m):
    stack=[]
    while m:
        stack.append((n,m))
        n,m=m,n%m
    if n>=0:
        x,y=1,0
    else:
        x,y=-1,0
    for i in range(len(stack)-1,-1,-1):
        n,m=stack[i]
        x,y=y,x-(n//m)*y
    return x,y

class MOD:
    def __init__(self,p,e=None):
        self.p=p
        self.e=e
        if self.e==None:
            self.mod=self.p
        else:
            self.mod=self.p**self.e

    def Pow(self,a,n):
        a%=self.mod
        if n>=0:
            return pow(a,n,self.mod)
        else:
            assert math.gcd(a,self.mod)==1
            x=Extended_Euclid(a,self.mod)[0]
            return pow(x,-n,self.mod)

    def Build_Fact(self,N):
        assert N>=0
        self.factorial=[1]
        if self.e==None:
            for i in range(1,N+1):
                self.factorial.append(self.factorial[-1]*i%self.mod)
        else:
            self.cnt=[0]*(N+1)
            for i in range(1,N+1):
                self.cnt[i]=self.cnt[i-1]
                ii=i
                while ii%self.p==0:
                    ii//=self.p
                    self.cnt[i]+=1
                self.factorial.append(self.factorial[-1]*ii%self.mod)
        self.factorial_inve=[None]*(N+1)
        self.factorial_inve[-1]=self.Pow(self.factorial[-1],-1)
        for i in range(N-1,-1,-1):
            ii=i+1
            while ii%self.p==0:
                ii//=self.p
            self.factorial_inve[i]=(self.factorial_inve[i+1]*ii)%self.mod

    def Fact(self,N):
        if N<0:
            return 0
        retu=self.factorial[N]
        if self.e!=None and self.cnt[N]:
            retu*=pow(self.p,self.cnt[N],self.mod)%self.mod
            retu%=self.mod
        return retu

    def Fact_Inve(self,N):
        if self.e!=None and self.cnt[N]:
            return None
        return self.factorial_inve[N]

    def Comb(self,N,K,divisible_count=False):
        if K==0:
            return 1
        if K<0 or K>N:
            return 0
        retu=self.factorial[N]*self.factorial_inve[K]%self.mod*self.factorial_inve[N-K]%self.mod
        if self.e!=None:
            cnt=self.cnt[N]-self.cnt[N-K]-self.cnt[K]
            if divisible_count:
                return retu,cnt
            else:
                retu*=pow(self.p,cnt,self.mod)
                retu%=self.mod
        return retu

def FFT(polynomial0,polynomial1,digit=10**5):
    def DFT(polynomial,n,inverse=False):
        if inverse:
            primitive_root=[math.cos(-i*2*math.pi/(1<<n))+math.sin(-i*2*math.pi/(1<<n))*1j for i in range(1<<n)]
        else:
            primitive_root=[math.cos(i*2*math.pi/(1<<n))+math.sin(i*2*math.pi/(1<<n))*1j for i in range(1<<n)]
        if inverse:
            for bit in range(1,n+1):
                a=1<<bit-1
                for i in range(1<<n-bit):
                    for j in range(a):
                        s=i*2*a+j
                        t=s+a
                        polynomial[s],polynomial[t]=polynomial[s]+polynomial[t]*primitive_root[j<<n-bit],polynomial[s]-polynomial[t]*primitive_root[j<<n-bit]
        else:
            for bit in range(n,0,-1):
                a=1<<bit-1
                for i in range(1<<n-bit):
                    for j in range(a):
                        s=i*2*a+j
                        t=s+a
                        polynomial[s],polynomial[t]=polynomial[s]+polynomial[t],primitive_root[j<<n-bit]*(polynomial[s]-polynomial[t])

    def FFT_(polynomial0,polynomial1):
        N0=len(polynomial0)
        N1=len(polynomial1)
        N=N0+N1-1
        n=(N-1).bit_length()
        polynomial0=polynomial0+[0]*((1<<n)-N0)
        polynomial1=polynomial1+[0]*((1<<n)-N1)
        DFT(polynomial0,n)
        DFT(polynomial1,n)
        fft=[x*y for x,y in zip(polynomial0,polynomial1)]
        DFT(fft,n,inverse=True)
        fft=[round((fft[i]/(1<<n)).real) for i in range(N)]
        return fft

    N0=len(polynomial0)
    N1=len(polynomial1)
    N=N0+N1-1
    polynomial00,polynomial01=[None]*N0,[None]*N0
    polynomial10,polynomial11=[None]*N1,[None]*N1
    for i in range(N0):
        polynomial00[i],polynomial01[i]=divmod(polynomial0[i],digit)
    for i in range(N1):
        polynomial10[i],polynomial11[i]=divmod(polynomial1[i],digit)
    polynomial=[0]*(N)
    a=digit**2-digit
    for i,x in enumerate(FFT_(polynomial00,polynomial10)):
        polynomial[i]+=x*a
    a=digit-1
    for i,x in enumerate(FFT_(polynomial01,polynomial11)):
        polynomial[i]-=x*a
    for i,x in enumerate(FFT_([x1+x2 for x1,x2 in zip(polynomial00,polynomial01)],[x1+x2 for x1,x2 in zip(polynomial10,polynomial11)])):
        polynomial[i]+=x*digit
    return polynomial

X,Y,Z=map(int,readline().split())
mod=10**9+7
MD=MOD(mod)
MD.Build_Fact(2*(X+Y+Z))
ans=0
dp=[MD.Comb(X+c-1,X)*MD.Comb(Y+c-1,Y)%mod*MD.Comb(Z+c-1,Z)%mod*MD.Fact_Inve(c)%mod for c in range(X+Y+Z+1)]
f=[MD.Fact_Inve(n)*(-1)**n%mod for n in range(X+Y+Z+1)]
f=FFT(f,dp)
for n in range(X+Y+Z+1):
    f[n]%=mod
ans=0
for n in range(X+Y+Z+1):
    ans+=f[n]*MD.Fact(n)%mod
ans%=mod
print(ans)
0