結果

問題 No.3178 free sort
ユーザー cologne
提出日時 2025-09-03 15:16:53
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 3,320 ms
コンパイル使用メモリ 281,240 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-03 15:16:59
合計ジャッジ時間 5,781 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <bits/stdc++.h>

using Mint = atcoder::modint998244353;
using namespace std;

Mint F(int N)
{
    Mint a = 1;
    for (int i = 1; i <= N; ++i)
        a *= i;
    return a;
}

Mint solve(vector<int> C)
{
    Mint ans = F(accumulate(C.begin(), C.end(), 0));
    for (int i = 0; i < 10; ++i)
        ans /= F(C[i]);
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    string S;
    cin >> S;
    vector<int> C(10);
    for (char c : S)
        C[c - '0']++;

    Mint ans = solve(C);

    if (C[0] > 0)
    {
        --C[0];
        ans -= solve(C);
    }

    cout << ans.val() << endl;
}
0