結果

問題 No.1933 ABC String
ユーザー ytqm3ytqm3
提出日時 2022-04-10 16:55:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,406 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 203,480 KB
実行使用メモリ 57,264 KB
最終ジャッジ日時 2023-08-26 06:56:56
合計ジャッジ時間 10,022 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
57,264 KB
testcase_01 AC 44 ms
50,180 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
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>
using i64=long long;
using u64=unsigned long long;
using namespace std;

template<u64 mod> struct modint{
  u64 val;
  modint(i64 val_=0):val((val_%i64(mod)+i64(mod))%i64(mod)){}
  modint operator-(){
    return (val==0)?0:mod-val;
  }
  modint operator+(modint rhs){
    return modint(*this)+=rhs;
  }
  modint operator-(modint rhs){
    return modint(*this)-=rhs;
  }
  modint operator*(modint rhs){
    return modint(*this)*=rhs;
  }
  modint operator/(modint rhs){
    return modint(*this)/=rhs;
  }
  modint pow(i64 rhs){
    modint res=1,now=(*this);
    while(rhs){
      res*=((rhs&1)?now:1),now*=now,rhs>>=1;
    }
    return res;
  }
  modint &operator+=(modint rhs){
    val+=rhs.val,val-=((val>=mod)?mod:0);
    return (*this);
  }
  modint &operator-=(modint rhs){
    val+=((val<rhs.val)?mod:0),val-=rhs.val;
    return (*this);
  }
  modint &operator*=(modint rhs){
    val=val*rhs.val%mod;
    return (*this);
  }
  modint &operator/=(modint rhs){
    return (*this)*=rhs.pow(mod-2);
  }
  bool operator==(modint rhs){
    return val==rhs.val;
  }
  bool operator!=(modint rhs){
    return val!=rhs.val;
  }
  friend std::ostream &operator<<(std::ostream& os,modint x){
    return os<<(x.val);
  }
  friend std::istream &operator>>(std::istream& is,modint& x){
    u64 t;
    is>>t,x=t;
    return is;
  }
};

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<0||k<0||n<k){
      return 0;
    }
    return dat[n]*idat[k]*idat[n-k];
  }
};

int main(){
  constexpr u64 mod=998244353;
  typedef modint<mod> mint;
  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;
  if(T<0 || U<0 || V<0){
    cout<<0<<endl;
    return 0;
  }
  comb<mint> Cb;
  mint ans=0;
  for(int i=0;i<=min(P,T);++i){
    for(int j=0;j<=min(Q,U);++j){
      for(int k=0;k<=min(R,V);++k){
        mint tmp=1;
        tmp*=Cb(P,i)*Cb(Q,j)*Cb(R,k);
        tmp*=Cb(N+(T-i)+j+k,T-i);
        tmp*=Cb(N+T+(U-j)+k,U-j);
        tmp*=Cb(N+T+U+(V-k),V-k);
        ans+=tmp*((i+j+k)%2?-1:1);
      }
    }
  }
  cout<<ans<<endl;
}
0