結果

問題 No.1302 Random Tree Score
ユーザー chineristACchineristAC
提出日時 2020-11-27 21:42:58
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 127 ms / 3,000 ms
コード長 826 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 82,140 KB
最終ジャッジ日時 2023-10-01 05:11:17
合計ジャッジ時間 4,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
80,380 KB
testcase_01 AC 85 ms
80,636 KB
testcase_02 AC 127 ms
81,576 KB
testcase_03 AC 113 ms
81,980 KB
testcase_04 AC 103 ms
81,540 KB
testcase_05 AC 115 ms
82,140 KB
testcase_06 AC 114 ms
82,108 KB
testcase_07 AC 106 ms
81,444 KB
testcase_08 AC 110 ms
81,764 KB
testcase_09 AC 117 ms
82,116 KB
testcase_10 AC 110 ms
81,804 KB
testcase_11 AC 100 ms
80,764 KB
testcase_12 AC 112 ms
81,984 KB
testcase_13 AC 84 ms
80,412 KB
testcase_14 AC 116 ms
82,056 KB
testcase_15 AC 115 ms
81,940 KB
testcase_16 AC 82 ms
80,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r, mod=998244353):#コンビネーションの高速計算 
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod =  998244353#出力の制限
N = 2*10**5
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

N = int(input())

pow_memo = [1]*N
for i in range(1,N):
    pow_memo[i] = (N * pow_memo[i-1]) % mod

res = 0
for i in range(N-1):
    tmp = cmb(N,i,mod) * pow_memo[N-2-i] * g2[N-2-i] % mod
    res += tmp
    res %= mod

res *= pow(pow_memo[N-2],mod-2,mod)
res %= mod
res *= g1[N-2]
print(res%mod)
0