結果
問題 |
No.1263 ご注文は数学ですか?
|
ユーザー |
![]() |
提出日時 | 2025-06-12 16:08:17 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,251 bytes |
コンパイル時間 | 381 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 55,864 KB |
最終ジャッジ日時 | 2025-06-12 16:08:24 |
合計ジャッジ時間 | 1,175 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 WA * 3 |
ソースコード
import sys from collections import Counter MOD = 10**9 + 7 def generate_partitions(n): partitions = [] def helper(n, max_part, current): if n == 0: partitions.append(current.copy()) return for i in range(min(max_part, n), 0, -1): current.append(i) helper(n - i, i, current) current.pop() helper(n, n, []) return partitions x = int(sys.stdin.readline()) partitions = generate_partitions(x) p = len(partitions) # Precompute factorials up to x fact = [1] * (x + 1) for i in range(1, x + 1): fact[i] = fact[i-1] * i % MOD x_fact = fact[x] x_fact_p = pow(x_fact, p, MOD) product_f = 1 for part in partitions: k = len(part) counts = Counter(part) sign = 1 if (x - k) % 2 == 0 else MOD - 1 numerator = (sign * fact[k-1]) % MOD denominator = 1 for m, cnt in counts.items(): m_fact = fact[m] term = pow(m_fact, cnt, MOD) term = term * fact[cnt] % MOD denominator = (denominator * term) % MOD inv_denominator = pow(denominator, MOD-2, MOD) f_i = (numerator * inv_denominator) % MOD product_f = (product_f * f_i) % MOD result = (product_f * x_fact_p) % MOD print(result)