結果

問題 No.1195 数え上げを愛したい(文字列編)
ユーザー dekomori_sanaedekomori_sanae
提出日時 2022-03-23 13:16:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,867 ms / 3,000 ms
コード長 2,032 bytes
コンパイル時間 3,027 ms
コンパイル使用メモリ 133,652 KB
実行使用メモリ 92,220 KB
最終ジャッジ日時 2024-04-19 18:50:33
合計ジャッジ時間 31,742 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,858 ms
92,220 KB
testcase_01 AC 1,867 ms
92,140 KB
testcase_02 AC 1,840 ms
92,152 KB
testcase_03 AC 467 ms
39,912 KB
testcase_04 AC 493 ms
44,420 KB
testcase_05 AC 1,841 ms
84,876 KB
testcase_06 AC 11 ms
10,696 KB
testcase_07 AC 9 ms
10,568 KB
testcase_08 AC 234 ms
26,468 KB
testcase_09 AC 1,824 ms
91,092 KB
testcase_10 AC 940 ms
55,112 KB
testcase_11 AC 1,808 ms
86,988 KB
testcase_12 AC 1,806 ms
82,716 KB
testcase_13 AC 991 ms
68,380 KB
testcase_14 AC 918 ms
49,296 KB
testcase_15 AC 946 ms
54,340 KB
testcase_16 AC 922 ms
49,972 KB
testcase_17 AC 238 ms
27,532 KB
testcase_18 AC 1,860 ms
83,016 KB
testcase_19 AC 1,798 ms
82,740 KB
testcase_20 AC 971 ms
68,648 KB
testcase_21 AC 1,822 ms
86,552 KB
testcase_22 AC 982 ms
64,920 KB
testcase_23 AC 9 ms
10,696 KB
testcase_24 AC 9 ms
10,752 KB
testcase_25 AC 9 ms
10,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
#include <atcoder/convolution>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 998244353;
const ll INF = 1e16;
 
const ll MAX = 300010;
 
ll fact[MAX];  // fact[i] : iの階乗のmod
ll inv[MAX];  // inv[i] : iの逆数のmod
ll invfact[MAX];  // invfact[i] : iの階乗の逆数のmod
 
void init() {
    fact[0] = 1;
    inv[0] = inv[1] = 1;
    invfact[0] = 1;
    for(ll i = 1; i < MAX; i++) {
        fact[i] = i * fact[i-1] % mod;
        if(i >= 2) {
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        }
        invfact[i] = invfact[i-1] * inv[i] % mod;
    }
}
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();
    
    init();
    
    vl a(26);
    for(char c : s) {
        a[(ll)(c - 'a')]++;
    }

    vvl dp(27, vl(n+1));  // dp[i][j] : iまでで、j個使うときの場合の数
    dp[0][0] = 1;
    rep(i, 26) {
        vl f(n+1);
        exrep(j, 0, a[i]) {
            f[j] = invfact[j];
        }
        vl g(n+1);
        exrep(j, 0, n) {
            g[j] = dp[i][j] * invfact[j] % mod;
        }
        vl h = convolution<mod>(f, g);
        exrep(j, 0, n) {
            dp[i+1][j] = fact[j] * h[j] % mod;
        }
    }
    
    ll ans = 0;
    exrep(j, 1, n) {
        ans += dp[26][j];
        ans %= mod;
    }
    
    out(ans);
    re0;
}
0