結果
問題 | No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│ |
ユーザー | vwxyz |
提出日時 | 2023-04-05 14:55:04 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,741 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 13,568 KB |
実行使用メモリ | 89,768 KB |
最終ジャッジ日時 | 2024-10-02 01:07:30 |
合計ジャッジ時間 | 10,119 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
12,160 KB |
testcase_01 | AC | 44 ms
12,416 KB |
testcase_02 | AC | 45 ms
12,544 KB |
testcase_03 | AC | 702 ms
18,284 KB |
testcase_04 | AC | 44 ms
12,416 KB |
testcase_05 | AC | 341 ms
14,720 KB |
testcase_06 | AC | 183 ms
13,696 KB |
testcase_07 | AC | 186 ms
13,696 KB |
testcase_08 | AC | 113 ms
13,184 KB |
testcase_09 | AC | 192 ms
13,952 KB |
testcase_10 | AC | 183 ms
13,568 KB |
testcase_11 | AC | 111 ms
13,056 KB |
testcase_12 | AC | 342 ms
14,848 KB |
testcase_13 | AC | 191 ms
14,080 KB |
testcase_14 | AC | 75 ms
12,672 KB |
testcase_15 | TLE | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
ソースコード
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)