結果
| 問題 |
No.3178 free sort
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-06-13 21:37:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,026 bytes |
| コンパイル時間 | 506 ms |
| コンパイル使用メモリ | 82,636 KB |
| 実行使用メモリ | 78,884 KB |
| 最終ジャッジ日時 | 2025-06-13 21:37:20 |
| 合計ジャッジ時間 | 4,770 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | WA * 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(1, 10):
if freq[j] == 0: continue
res *= mcomb.ifact[freq[j]]
res %= MOD
ans += res
ans %= MOD
freq[i] += 1
print(ans)
norioc