結果
問題 |
No.3178 free sort
|
ユーザー |
![]() |
提出日時 | 2025-06-13 21:43:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 1,023 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 82,756 KB |
実行使用メモリ | 78,804 KB |
最終ジャッジ日時 | 2025-06-13 21:43:50 |
合計ジャッジ時間 | 4,828 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 40 |
ソースコード
from collections import Counter class ModComb: def __init__(self, n: int, mod: int): fact = [0] * (n+1) fact[0] = 1 for i in range(1, n+1): fact[i] = i * fact[i-1] % mod ifact = [0] * (n+1) ifact[n] = pow(fact[n], mod-2, mod) for i in range(n, 0, -1): ifact[i-1] = ifact[i] * i % mod self.fact = fact self.ifact = ifact self.mod = mod def __call__(self, n: int, k: int) -> int: if n < 0 or k > n: return 0 return (self.fact[n] * self.ifact[k] % self.mod) * self.ifact[n-k] % self.mod MOD = 998244353 N = input() mcomb = ModComb(2 * 10**5, MOD) ds = [int(c) for c in N] freq = Counter(ds) ans = 0 for i in range(1, 10): if freq[i] == 0: continue freq[i] -= 1 tot = sum(freq.values()) res = mcomb.fact[tot] for j in range(10): if freq[j] == 0: continue res *= mcomb.ifact[freq[j]] res %= MOD ans += res ans %= MOD freq[i] += 1 print(ans)