結果

問題 No.1933 ABC String
ユーザー ytqm3ytqm3
提出日時 2022-05-06 18:20:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,097 bytes
コンパイル時間 4,802 ms
コンパイル使用メモリ 263,788 KB
実行使用メモリ 31,408 KB
最終ジャッジ日時 2023-09-19 07:29:05
合計ジャッジ時間 9,676 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
30,752 KB
testcase_01 AC 40 ms
26,420 KB
testcase_02 AC 42 ms
26,464 KB
testcase_03 AC 40 ms
26,548 KB
testcase_04 AC 40 ms
26,468 KB
testcase_05 AC 40 ms
26,676 KB
testcase_06 AC 39 ms
26,424 KB
testcase_07 AC 40 ms
26,492 KB
testcase_08 AC 49 ms
26,484 KB
testcase_09 AC 55 ms
26,420 KB
testcase_10 AC 54 ms
26,484 KB
testcase_11 AC 87 ms
26,596 KB
testcase_12 AC 52 ms
26,552 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T> struct comb{
  vector<T> dat,idat;
  comb(int mx=3000000):dat(mx+1,1),idat(mx+1,1){
    for(int i=1;i<=mx;++i){
      dat[i]=dat[i-1]*i;
    }
    idat[mx]/=dat[mx];
    for(int i=mx;i>0;--i){
      idat[i-1]=idat[i]*i;
    }
  }
  T operator()(int n,int k){
    if(n==k){
      return 1;
    }
    if(n<0||k<0||n<k){
      return 0;
    }
    return dat[n]*idat[k]*idat[n-k];
  }
};

int main(){
  string S;
  int A,B,C;
  cin>>S>>A>>B>>C;
  int N=S.size();
  int P=count(S.begin(),S.end(),'a'),Q=count(S.begin(),S.end(),'b'),R=count(S.begin(),S.end(),'c');
  int T=A-P,U=B-Q,V=C-R;
  comb<mint> Cb;
  auto f = [&](int n, int m) { return Cb(n+m-1,m-1); };
  mint ans=0;
  for(int k = 0; k <= T+U; k++) {
    mint cnt1 = 0,cnt2=0;
    for(int i = 0; i <= k; i++) {
      cnt1+=f(i,R)*f(V,P+Q+T+U-i+1);
    }
    for(int i = max(0,k-U); i <= T && i <= k; i++) {
      cnt2+=Cb(k,i)*f(T-i,Q)*f(U-(k-i),P);
    }
    ans += cnt1*cnt2;
  }
  cout<<ans.val()<<endl;
}
0