結果

問題 No.1933 ABC String
ユーザー ytqm3ytqm3
提出日時 2022-05-06 18:24:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,070 bytes
コンパイル時間 4,809 ms
コンパイル使用メモリ 262,268 KB
実行使用メモリ 53,832 KB
最終ジャッジ日時 2023-09-19 07:33:56
合計ジャッジ時間 9,453 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,832 KB
testcase_01 AC 39 ms
26,628 KB
testcase_02 AC 41 ms
26,552 KB
testcase_03 AC 39 ms
26,576 KB
testcase_04 AC 38 ms
26,556 KB
testcase_05 AC 37 ms
26,440 KB
testcase_06 AC 38 ms
26,504 KB
testcase_07 AC 40 ms
26,616 KB
testcase_08 AC 47 ms
26,496 KB
testcase_09 AC 54 ms
26,500 KB
testcase_10 AC 52 ms
26,412 KB
testcase_11 AC 85 ms
26,420 KB
testcase_12 AC 50 ms
26,492 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 j=max(0,k-U);j<=min(T,k);j++){
      cnt2+=Cb(k,j)*f(T-j,Q)*f(U-(k-j),P);
    }
    ans+=cnt1*cnt2;
  }
  cout<<ans.val()<<endl;
}
0