結果

問題 No.3178 free sort
ユーザー eve__fuyuki
提出日時 2025-06-27 16:06:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 198,132 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-06-27 16:06:05
合計ジャッジ時間 4,389 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

void fast_io() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
}

#include <atcoder/modint>
using mint = atcoder::modint998244353;
mint fact[500001], inv_fact[500001];
void init() {
	fact[0] = 1;
	for (int i = 1; i < 500001; ++i) {
		fact[i] = fact[i - 1] * i;
	}
	inv_fact[500000] = fact[500000].inv();
	for (int i = 499999; i >= 0; --i) {
		inv_fact[i] = inv_fact[i + 1] * (i + 1);
	}
}
int main() {
	fast_io();
	init();
	string n;
	cin >> n;
	int cnt[10] = {};
	for (char c : n) {
		cnt[c - '0']++;
	}
	int len = n.size();
	mint tot = fact[len];
	for (int i = 0; i < 10; ++i) {
		tot *= inv_fact[cnt[i]];
	}
	if (cnt[0] == 0) {
		cout << tot.val() << endl;
		return 0;
	}
	mint ng = fact[len - 1] * inv_fact[cnt[0] - 1];
	for (int i = 1; i < 10; ++i) {
		ng *= inv_fact[cnt[i]];
	}
	mint ans = tot - ng;
	cout << ans.val() << endl;
}
0