結果

問題 No.3178 free sort
ユーザー prin_kemkem
提出日時 2025-06-13 21:41:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 1,380 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 252,760 KB
最終ジャッジ日時 2025-06-13 21:41:40
合計ジャッジ時間 16,063 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque, Counter
# from functools import cache
# import copy
from itertools import combinations, permutations, product, accumulate, groupby, chain
# from more_itertools import distinct_permutations
from heapq import heapify, heappop, heappush, heappushpop
import math
import bisect
# from pprint import pprint
from random import randint, shuffle, randrange
# from sortedcontainers import SortedSet, SortedList, SortedDict
import sys
sys.setrecursionlimit(5000)
input = lambda: sys.stdin.readline().rstrip('\n')
inf = float('inf')
mod1 = 10**9+7
mod2 = 998244353
def ceil_div(x, y): return -(-x//y)

#################################################   

def cmb(n, r):
    if r < 0 or r > n:
        return 0
    r = min(r, n-r)
    return fact[n]*factinv[r]%p*factinv[n-r]%p

def pmt(n, r):
    if r < 0 or r > n:
        return 0
    return fact[n]*factinv[n-r]%p

p = mod2
N = 10**6 #Nは必要分だけ用意する
fact = [1, 1] #fact[n]: n! mod p
factinv = [1, 1] #factinv[n]: n!^(-1) mod p
inv = [0, 1] #inv[n]: n^(-1) mod p

for i in range(2, N+1):
    fact.append((fact[-1]*i)%p)
    inv.append((-inv[p%i]*(p//i))%p)
    factinv.append((factinv[-1]*inv[-1])%p)

N = input()
D = len(N)
cnt = Counter(map(int, N))
ans = cmb(D-1, cnt[0])
D -= cnt[0]
for k in range(1, 10):
    ans *= cmb(D, cnt[k])
    ans %= mod2
    D -= cnt[k]
print(ans)
0