結果

問題 No.3178 free sort
コンテスト
ユーザー クロさん
提出日時 2025-12-08 13:53:15
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,272 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,175 ms
コンパイル使用メモリ 255,788 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-08 13:53:22
合計ジャッジ時間 6,786 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
static const double pi = 3.141592653589793;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll imod = 998244353;
using mint = modint998244353;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
ll P(ll x, ll n) {
  ll ret = 1;
    while (n > 0) {
      if (n & 1) ret *= x;
      x *= x;
      n >>= 1;
  }
  return ret;
}

void seek(bool f){
  cout << (f ? "Yes" : "No") << endl;
}

int main(){
	string s;
	cin >> s;
	ll N = (ll)s.size();
	vector<ll> cnt(10, 0);
	rep(i, N){
		cnt[s[i] - '0']++;
	}
	if(cnt[0] == N){
		cout << 1 << endl;
	}
	vector<mint> fact(N + 1, 0), inv(N + 1, 0), fact_inv(N + 1, 0);
	fact[0] = fact[1] = 1;
	fact_inv[0] = fact_inv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i <= N; i++){
		fact[i] = fact[i - 1] * i;
    	inv[i] = imod - inv[imod % i] * (imod / i);
    	fact_inv[i] = fact_inv[i - 1] * inv[i];
	}
	
	if(cnt[0] == N){
		cout << 1 << endl;
	}
	else{
		mint ans = 0;
		for(ll i = 1; i <= 9; i++){
			mint res = fact[N - 1];
			for(ll j = 0; j <= 9; j++){
				res *= fact_inv[cnt[j] - (i == j ? 1 : 0)];
			}
			ans += res;
		}
		cout << ans.val() << endl;
	}
}
0