結果

問題 No.1933 ABC String
ユーザー ytqm3ytqm3
提出日時 2022-04-10 21:49:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,677 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 203,972 KB
実行使用メモリ 36,360 KB
最終ジャッジ日時 2023-08-26 06:57:20
合計ジャッジ時間 8,750 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
36,360 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

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;
  }
};

int main(){
  constexpr u64 mod=998244353;
  typedef modint<mod> mint;
  string S;
  int A,B,C;
  cin>>S>>A>>B>>C;
  assert(A<=80 && B<=80 && C<=80);
  int N=S.size();
  vector<array<array<array<mint,81>,81>,81>> dp(N+5);
  for(int i=0;i<=N;++i){
    for(int j=0;j<=80;++j){
      for(int k=0;k<=80;++k){
        for(int l=0;l<=80;++l){
          dp[i][j][k][l]=0;
        }
      }
    }
  }
  dp[0][0][0][0]=1;
  for(int s=0;s<A+B+C;++s){
    for(int a=0;a<=min(s,A);++a){
      for(int b=0;b<=min(s-a,B);++b){
        int c=s-a-b;
        if(C<c){
          continue;
        }
        for(int i=0;i<N;++i){
          if(S[i]=='a'){
            dp[i+1][a+1][b][c]+=dp[i][a][b][c];
            dp[i][a][b+1][c]+=dp[i][a][b][c];
            dp[i][a][b][c+1]+=dp[i][a][b][c];
          }
          if(S[i]=='b'){
            dp[i+1][a][b+1][c]+=dp[i][a][b][c];
            dp[i][a+1][b][c]+=dp[i][a][b][c];
            dp[i][a][b][c+1]+=dp[i][a][b][c];
          }
          if(S[i]=='c'){
            dp[i+1][a][b][c+1]+=dp[i][a][b][c];
            dp[i][a+1][b][c]+=dp[i][a][b][c];
            dp[i][a][b+1][c]+=dp[i][a][b][c];
          }
        }
        dp[N][a+1][b][c]+=dp[N][a][b][c];
        dp[N][a][b+1][c]+=dp[N][a][b][c];
        dp[N][a][b][c+1]+=dp[N][a][b][c];
      }
    }
  }
  cout<<dp[N][A][B][C]<<endl;
}
0