結果
問題 | No.1302 Random Tree Score |
ユーザー | convexineq |
提出日時 | 2020-11-28 00:11:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,490 bytes |
コンパイル時間 | 292 ms |
コンパイル使用メモリ | 82,912 KB |
実行使用メモリ | 262,996 KB |
最終ジャッジ日時 | 2024-07-26 21:19:35 |
合計ジャッジ時間 | 8,433 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
70,384 KB |
testcase_01 | AC | 45 ms
62,696 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
ソースコード
ROOT = 3 MOD = 998244353 roots = [pow(ROOT,(MOD-1)>>i,MOD) for i in range(24)] # 1 の 2^i 乗根 iroots = [pow(x,MOD-2,MOD) for x in roots] # 1 の 2^i 乗根の逆元 def untt(a,n): for i in range(n): m = 1<<(n-i-1) for s in range(1<<i): w_N = 1 s *= m*2 for p in range(m): a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m])%MOD, (a[s+p]-a[s+p+m])*w_N%MOD w_N = w_N*roots[n-i]%MOD def iuntt(a,n): for i in range(n): m = 1<<i for s in range(1<<(n-i-1)): w_N = 1 s *= m*2 for p in range(m): a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m]*w_N)%MOD, (a[s+p]-a[s+p+m]*w_N)%MOD w_N = w_N*iroots[i+1]%MOD inv = pow((MOD+1)//2,n,MOD) for i in range(1<<n): a[i] = a[i]*inv%MOD def convolution(a,b): la = len(a) lb = len(b) if min(la, lb) <= 50: if la < lb: la,lb = lb,la a,b = b,a res = [0]*(la+lb-1) for i in range(la): for j in range(lb): res[i+j] += a[i]*b[j] res[i+j] %= MOD return res deg = la+lb-2 n = deg.bit_length() N = 1<<n a += [0]*(N-len(a)) b += [0]*(N-len(b)) untt(a,n) untt(b,n) for i in range(N): a[i] = a[i]*b[i]%MOD iuntt(a,n) return a[:deg+1] SIZE=10**5+5 inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): fac[i] = fac[i-1]*i%MOD finv[-1] = pow(fac[-1],MOD-2,MOD) for i in range(SIZE-1,0,-1): finv[i-1] = finv[i]*i%MOD inv[i] = finv[i]*fac[i-1]%MOD def pow_poly(f,a,N): v = f ans = [1] while a: if a&1: ans = convolution(v,ans)[:N] v = convolution(v[:],v[:])[:N] a >>= 1 return ans # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline #n = int(readline()) n, = map(int,readline().split()) #*a, = map(int,readline().split()) def mul_poly(f,g): df,dg = len(f),len(g) res = [0]*(df+dg-1) for i in range(df): for j in range(dg): res[i+j] += f[i]*g[j] res[i+j] %= MOD return res f = [(i+1)*inv[i]%MOD for i in range(n)] f[0] = 1 #print(f) g = pow_poly(f,n,n) #print(g) print(g[n-2]*fac[n-2]%MOD*pow(n,MOD-1-n+2,MOD)%MOD)