結果
問題 | No.8046 yukicoderの過去問 |
ユーザー | vwxyz |
提出日時 | 2023-04-22 06:29:41 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,333 bytes |
コンパイル時間 | 204 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 308,944 KB |
最終ジャッジ日時 | 2024-11-06 21:30:07 |
合計ジャッジ時間 | 6,671 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
ソースコード
import bisect import copy import decimal import fractions import functools import heapq import itertools import math import random import sys 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 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%mod a=digit-1 for i,x in enumerate(FFT_(polynomial01,polynomial11)): polynomial[i]-=x*a%mod 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%mod polynomial[i]%=mod return polynomial def Bostan_Mori(poly_nume,poly_deno,N,mod=0,fft=False,ntt=False): if ntt: convolve=NTT elif fft: convolve=FFT else: def convolve(poly_nume,poly_deno): conv=[0]*(len(poly_nume)+len(poly_deno)-1) for i in range(len(poly_nume)): for j in range(len(poly_deno)): x=poly_nume[i]*poly_deno[j] if mod: x%=mod conv[i+j]+=x if mod: for i in range(len(conv)): conv[i]%=mod return conv while N: poly_deno_=[-x if i%2 else x for i,x in enumerate(poly_deno)] if N%2: poly_nume=convolve(poly_nume,poly_deno_)[1::2] else: poly_nume=convolve(poly_nume,poly_deno_)[::2] poly_deno=convolve(poly_deno,poly_deno_)[::2] if fft and mod: for i in range(len(poly_nume)): poly_nume[i]%=mod for i in range(len(poly_deno)): poly_deno[i]%=mod N//=2 return poly_nume[0] N=int(readline()) K=int(readline()) mod=10**9+7 nume=[1] deno=[0]*(10**5+1) deno[0]=1 for x in map(int,readline().split()): deno[x]=mod-1 ans=Bostan_Mori(nume,deno,N,mod=10**9+7,fft=True) print(ans)