結果

問題 No.3178 free sort
ユーザー jiangxinyang
提出日時 2025-06-13 21:53:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 195,252 KB
実行使用メモリ 9,076 KB
最終ジャッジ日時 2025-06-13 21:53:24
合計ジャッジ時間 3,333 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
const int N = 200005;
const int INF = 0x3f3f3f3f;
ll powmod(ll x, ll y) {
    ll res = 1;
    while (y) {
        if (y & 1) res = res * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return res;
}
ll fac[N], inv[N], jv[N];
void com_init(int n) {
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    jv[0] = fac[0] = 1;
    for (int i = 1; i <= n; i++) {
        fac[i] = fac[i - 1] * i % mod;
        jv[i] = jv[i - 1] * inv[i] % mod;
    }
}
ll com(ll n, ll m) {
    if (n < m || m < 0) return 0;
    return fac[n] * jv[n - m] % mod * jv[m] % mod;
}
int cnt[N];
ll solve() {
    int tot = 0;
    for (int i = 0; i < 10; i++) tot += cnt[i];
    ll res = fac[tot];
    for (int i = 0; i < 10; i++) res = res * jv[cnt[i]] % mod;
    return res;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    com_init(N - 5);
    string s;
    cin >> s;
    for (auto x : s) cnt[x - '0']++;
    ll res = solve();
    if (cnt[0] > 0) {
        cnt[0]--;
        res = (res - solve() + mod) % mod;
    }
    cout << res << "\n";
    return 0;
}
0