結果
問題 |
No.3178 free sort
|
ユーザー |
![]() |
提出日時 | 2025-06-13 21:25:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 1,481 bytes |
コンパイル時間 | 5,054 ms |
コンパイル使用メモリ | 335,424 KB |
実行使用メモリ | 42,820 KB |
最終ジャッジ日時 | 2025-06-13 21:25:22 |
合計ジャッジ時間 | 9,096 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 40 |
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; using mint = modint998244353; struct Comb { vector<mint> fact, ifact; int MAX_COM; Comb() {} Comb(int n, int mod) { MAX_COM = n; init(mod, MAX_COM); } void init(long long MOD, long long MAX_COM) { int n = MAX_COM; assert(n < MOD); fact = vector<mint>(n + 1); ifact = vector<mint>(n + 1); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(long long n, long long k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; Comb comb(5000010, 998244353); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(12); string s; cin >> s; vector<int> a(10); for (auto c : s) { a[c - '0']++; } int n = s.size(); mint ans = 0; rep(i, 1, 10) { if (a[i] == 0) continue; a[i]--; mint ad = 1; int m = n - 1; rep(i, 0, 10) { ad *= comb(m, a[i]); m -= a[i]; } ans += ad; a[i]++; } cout << ans.val() << endl; }