結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    const int n = s.size();
    array<int, 10> cnt{};
    for(auto c : s) cnt[c - '0']++;
    vector<mint> fact(n + 1);
    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint::raw(i);
    mint ans;
    for(int i = 1; i < 10; i++){
        if(cnt[i] == 0) continue;
        cnt[i]--;
        mint div = 1;
        for(int j = 0; j < 10; j++) div *= fact[cnt[j]];
        ans += div.inv();
        cnt[i]++;
    }
    ans *= fact[n - 1];
    cout << ans.val() << '\n';
}
0