結果

問題 No.1195 数え上げを愛したい(文字列編)
ユーザー auauaauaua
提出日時 2020-08-22 17:51:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,416 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 170,440 KB
実行使用メモリ 87,888 KB
最終ジャッジ日時 2024-04-23 11:41:09
合計ジャッジ時間 10,501 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=998244353;
const int MAX=300010;

ll rui(ll a,ll b){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1)res=res*x%mod;
        x=x*x%mod;
        b/=2;
    }
    return res;
}

signed main(){
    string s;cin>>s;
    ll n=s.size();
    vector<ll>a(26);
    rep(i,n){
        a[s[i]-'a']++;
    }
    vector<ll>kai(n+1);
    kai[0]=1;
    REP(i,1,n+1){
        kai[i]=kai[i-1]*i%mod;
    }
    vector<ll>inv(n+1);
    rep(i,n+1){
        inv[i]=rui(kai[i],mod-2);
    }
    vector<vector<ll> >dp(27,vector<ll>(n+1));
    dp[0][0]=1;
    rep(i,26){
        rep(j,n+1){
            if(dp[i][j]==0)continue;
            rep(k,a[i]+1){
                if(k+j<=n){
                    dp[i+1][k+j]=(dp[i][j]*inv[k]%mod+dp[i+1][k+j])%mod;
                }
            }
        }
    }
    ll ans=0;
    REP(i,1,n+1){
        ans=(ans+kai[i]*dp[26][i]%mod)%mod;
    }
    cout<<ans<<endl;
}
0