結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
26,408 KB
testcase_01 AC 41 ms
26,588 KB
testcase_02 AC 42 ms
26,492 KB
testcase_03 AC 40 ms
26,452 KB
testcase_04 AC 41 ms
26,444 KB
testcase_05 AC 41 ms
26,572 KB
testcase_06 AC 40 ms
26,528 KB
testcase_07 AC 41 ms
26,772 KB
testcase_08 AC 49 ms
26,536 KB
testcase_09 AC 56 ms
26,488 KB
testcase_10 AC 55 ms
26,488 KB
testcase_11 AC 87 ms
26,532 KB
testcase_12 AC 51 ms
26,512 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