結果
問題 | No.1387 Mitarushi's Remodeling |
ユーザー | chineristAC |
提出日時 | 2021-02-07 22:03:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,044 ms / 2,000 ms |
コード長 | 2,580 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 300,748 KB |
最終ジャッジ日時 | 2024-07-04 15:36:01 |
合計ジャッジ時間 | 62,273 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
71,168 KB |
testcase_01 | AC | 79 ms
71,040 KB |
testcase_02 | AC | 79 ms
71,424 KB |
testcase_03 | AC | 75 ms
71,168 KB |
testcase_04 | AC | 77 ms
70,912 KB |
testcase_05 | AC | 81 ms
70,784 KB |
testcase_06 | AC | 78 ms
71,168 KB |
testcase_07 | AC | 80 ms
70,784 KB |
testcase_08 | AC | 147 ms
99,584 KB |
testcase_09 | AC | 139 ms
99,840 KB |
testcase_10 | AC | 143 ms
99,584 KB |
testcase_11 | AC | 141 ms
99,584 KB |
testcase_12 | AC | 139 ms
99,584 KB |
testcase_13 | AC | 142 ms
99,840 KB |
testcase_14 | AC | 932 ms
300,744 KB |
testcase_15 | AC | 855 ms
300,488 KB |
testcase_16 | AC | 857 ms
299,852 KB |
testcase_17 | AC | 844 ms
300,100 KB |
testcase_18 | AC | 897 ms
300,236 KB |
testcase_19 | AC | 862 ms
300,228 KB |
testcase_20 | AC | 996 ms
300,496 KB |
testcase_21 | AC | 870 ms
300,228 KB |
testcase_22 | AC | 876 ms
300,740 KB |
testcase_23 | AC | 861 ms
300,492 KB |
testcase_24 | AC | 883 ms
300,228 KB |
testcase_25 | AC | 912 ms
300,744 KB |
testcase_26 | AC | 900 ms
300,228 KB |
testcase_27 | AC | 913 ms
299,976 KB |
testcase_28 | AC | 894 ms
299,716 KB |
testcase_29 | AC | 859 ms
300,488 KB |
testcase_30 | AC | 905 ms
300,104 KB |
testcase_31 | AC | 918 ms
300,108 KB |
testcase_32 | AC | 911 ms
300,644 KB |
testcase_33 | AC | 903 ms
299,976 KB |
testcase_34 | AC | 957 ms
300,292 KB |
testcase_35 | AC | 954 ms
300,364 KB |
testcase_36 | AC | 1,044 ms
300,236 KB |
testcase_37 | AC | 1,033 ms
299,988 KB |
testcase_38 | AC | 974 ms
300,120 KB |
testcase_39 | AC | 954 ms
300,740 KB |
testcase_40 | AC | 1,037 ms
300,748 KB |
testcase_41 | AC | 1,011 ms
300,232 KB |
testcase_42 | AC | 954 ms
300,100 KB |
testcase_43 | AC | 1,021 ms
300,108 KB |
testcase_44 | AC | 954 ms
300,424 KB |
testcase_45 | AC | 948 ms
300,488 KB |
testcase_46 | AC | 1,041 ms
300,232 KB |
testcase_47 | AC | 991 ms
300,232 KB |
testcase_48 | AC | 1,005 ms
300,100 KB |
testcase_49 | AC | 897 ms
300,104 KB |
testcase_50 | AC | 1,010 ms
300,340 KB |
testcase_51 | AC | 967 ms
300,240 KB |
testcase_52 | AC | 1,018 ms
300,232 KB |
testcase_53 | AC | 1,027 ms
300,332 KB |
testcase_54 | AC | 1,036 ms
299,716 KB |
testcase_55 | AC | 1,016 ms
300,236 KB |
testcase_56 | AC | 1,030 ms
300,488 KB |
testcase_57 | AC | 996 ms
299,716 KB |
testcase_58 | AC | 970 ms
300,236 KB |
testcase_59 | AC | 907 ms
299,980 KB |
testcase_60 | AC | 964 ms
300,228 KB |
testcase_61 | AC | 963 ms
299,588 KB |
testcase_62 | AC | 973 ms
300,744 KB |
testcase_63 | AC | 909 ms
299,604 KB |
testcase_64 | AC | 900 ms
299,716 KB |
testcase_65 | AC | 920 ms
299,960 KB |
testcase_66 | AC | 960 ms
300,232 KB |
testcase_67 | AC | 917 ms
299,724 KB |
testcase_68 | AC | 899 ms
299,876 KB |
testcase_69 | AC | 906 ms
298,040 KB |
ソースコード
mod = 998244353 omega = pow(3,119,mod) rev_omega = pow(omega,mod-2,mod) N = 5*10**5 g1 = [1]*(N+1) # 元テーブル g2 = [1]*(N+1) #逆元テーブル inv = [1]*(N+1) #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inv[i]=( ( -inv[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inv[i]) % mod ) inv[0]=0 def _ntt(f,L,reverse=False): F=[f[i] for i in range(L)] n = L.bit_length() - 1 base = omega if reverse: base = rev_omega if not n: return F size = 2**n wj = pow(base,2**22,mod) res = [0]*2**n for i in range(n,0,-1): use_omega = pow(base,2**(22+i-n),mod) res = [0]*2**n size //= 2 w = 1 for j in range(0,L//2,size): for a in range(size): res[a+j] = (F[a+2*j] + w * F[a+size+2*j]) % mod t = (w * wj) % mod res[L//2+a+j] = (F[a+2*j] + t * F[a+size+2*j]) % mod w = (w * use_omega) % mod F = res return res def ntt(f,L=0): l = len(f) if not L: L = 1<<((l-1).bit_length()) while len(f)<L: f.append(0) f=f[:L] F = _ntt(f,L) return F def intt(f,L=0): l = len(f) if not L: L = 1<<((l-1).bit_length()) while len(f)<L: f.append(0) f=f[:L] F = _ntt(f,L,reverse=True) inv = pow(L,mod-2,mod) for i in range(L): F[i] *= inv F[i] %= mod return F def convolve(f,g,limit): l = len(f)+len(g)-1 L = 1<<((l-1).bit_length()) F = ntt(f,L) G = ntt(g,L) H = [(F[i] * G[i]) % mod for i in range(L)] h = intt(H,L) return h[:limit] inv2 = pow(2,mod-2,mod) N,K = map(int,input().split()) M = list(map(int,input().split())) c = 1 for m in M: c *= m c %= mod M = [(M[i]+1)*inv2 % mod for i in range(N)] Mi = [M[N-i-1] for i in range(N)] conv = convolve(M,Mi,2*N)[N-1:] check = [conv[i]*4 % mod for i in range(N)] imos = [g2[i] for i in range(N)] for i in range(1,N): imos[i] += imos[i-1] imos[i] %= mod prod = [N-1 for i in range(K+1)] for i in range(2,K+1): prod[i] = (prod[i-1] * (N-i)) % mod prod[0] = 0 imos_prod = [prod[i] for i in range(K+1)] for i in range(1,K+1): imos_prod[i] += imos_prod[i-1] imos_prod[i] %= mod res = imos_prod[K] * conv[N-1] % mod for x in range(1,N-1): L = 1 R = min(K,N-1-x) tmp = g1[N-1-x] * (imos[N-1-x-L] - imos[N-1-x-R] + g2[N-1-x-R]) tmp2 = (imos_prod[K] - tmp) % mod res += tmp2 * conv[x] res %= mod print(res*c % mod)