結果
問題 | No.1307 Rotate and Accumulate |
ユーザー | vwxyz |
提出日時 | 2023-12-16 05:36:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,773 ms / 5,000 ms |
コード長 | 2,714 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 306,524 KB |
最終ジャッジ日時 | 2024-09-27 07:25:14 |
合計ジャッジ時間 | 19,113 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,928 KB |
testcase_01 | AC | 39 ms
53,996 KB |
testcase_02 | AC | 40 ms
54,468 KB |
testcase_03 | AC | 53 ms
65,160 KB |
testcase_04 | AC | 62 ms
69,072 KB |
testcase_05 | AC | 60 ms
68,696 KB |
testcase_06 | AC | 54 ms
64,600 KB |
testcase_07 | AC | 38 ms
53,592 KB |
testcase_08 | AC | 1,709 ms
299,544 KB |
testcase_09 | AC | 1,682 ms
298,500 KB |
testcase_10 | AC | 762 ms
253,816 KB |
testcase_11 | AC | 766 ms
248,972 KB |
testcase_12 | AC | 752 ms
252,660 KB |
testcase_13 | AC | 154 ms
86,136 KB |
testcase_14 | AC | 385 ms
144,876 KB |
testcase_15 | AC | 1,773 ms
306,172 KB |
testcase_16 | AC | 1,764 ms
306,256 KB |
testcase_17 | AC | 1,772 ms
306,236 KB |
testcase_18 | AC | 1,765 ms
303,732 KB |
testcase_19 | AC | 1,767 ms
306,524 KB |
testcase_20 | AC | 1,754 ms
306,228 KB |
testcase_21 | AC | 37 ms
53,496 KB |
ソースコード
import sys readline=sys.stdin.readline import math 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 if digit: 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 for i,x in enumerate(FFT_(polynomial00,polynomial10)): polynomial[i]+=x*(digit**2-digit) for i,x in enumerate(FFT_(polynomial01,polynomial11)): polynomial[i]-=x*(digit-1) 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 else: polynomial=FFT_(polynomial0,polynomial1) return polynomial N,Q=map(int,readline().split()) A=list(map(int,readline().split())) R=[0]*N for r in map(int,readline().split()): R[(-r)%N]+=1 ans_lst=[0]*N for i,ans in enumerate(FFT(A,R)): ans_lst[i%N]+=ans print(*ans_lst)