結果
| 問題 |
No.3178 free sort
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2025-06-27 16:01:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 863 bytes |
| コンパイル時間 | 1,943 ms |
| コンパイル使用メモリ | 198,012 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-27 16:01:51 |
| 合計ジャッジ時間 | 3,796 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | WA * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void fast_io() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
#include <atcoder/modint>
using mint = atcoder::modint998244353;
mint fact[500001], inv_fact[500001];
void init() {
fact[0] = 1;
for (int i = 1; i < 500001; ++i) {
fact[i] = fact[i - 1] * i;
}
inv_fact[500000] = fact[500000].inv();
for (int i = 499999; i >= 0; --i) {
inv_fact[i] = inv_fact[i + 1] * (i + 1);
}
}
int main() {
fast_io();
init();
string n;
cin >> n;
int cnt[10] = {};
for (char c : n) {
cnt[c - '0']++;
}
int len = n.size();
mint p1 = fact[len], p2 = fact[len - 1];
for (int i = 0; i < 10; i++) {
p1 *= inv_fact[cnt[i]];
if (i == 0 && cnt[i] > 0) {
p2 *= inv_fact[cnt[i] - 1];
}
}
if (cnt[0] == 0) {
cout << p1.val() << endl;
} else {
mint ans = p1 - p2;
cout << ans.val() << endl;
}
}
eve__fuyuki