結果

問題 No.1677 mæx
ユーザー monnumonnu
提出日時 2021-09-16 21:49:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 3,551 ms
コンパイル使用メモリ 228,152 KB
実行使用メモリ 7,652 KB
最終ジャッジ日時 2023-09-12 04:14:39
合計ジャッジ時間 5,358 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 10 ms
6,184 KB
testcase_05 AC 11 ms
6,256 KB
testcase_06 AC 11 ms
6,260 KB
testcase_07 AC 11 ms
6,196 KB
testcase_08 AC 10 ms
6,208 KB
testcase_09 AC 11 ms
6,284 KB
testcase_10 AC 11 ms
6,192 KB
testcase_11 AC 10 ms
6,332 KB
testcase_12 AC 10 ms
6,196 KB
testcase_13 AC 11 ms
6,340 KB
testcase_14 AC 11 ms
6,284 KB
testcase_15 AC 11 ms
6,384 KB
testcase_16 AC 11 ms
6,184 KB
testcase_17 AC 11 ms
6,360 KB
testcase_18 AC 11 ms
6,340 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 12 ms
7,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 2000005
//#define MOD 1000000007
#define MOD 998244353
#define INF 1000000000
//#define INF 1000000000000000000

int mex(int a,int b){
  int ret=0;
  while(ret==a||ret==b){
    ++ret;
  }
  return ret;
}

vector<ll> dfs(string &S,int &i){
  if(S[i]=='0'){
    ++i;
    return {1,0,0};
  }else if(S[i]=='1'){
    ++i;
    return {0,1,0};
  }else if(S[i]=='2'){
    ++i;
    return {0,0,1};
  }else if(S[i]=='?'){
    ++i;
    return {1,1,1};
  }

  char c=S[i+1];
  i+=4;
  vector<ll> a=dfs(S,i);
  assert(S[i]==',');
  ++i;
  vector<ll> b=dfs(S,i);
  ++i;

  vector<ll> ret(3,0);
  for(int j=0;j<3;j++){
    for(int k=0;k<3;k++){
      if(c=='a'||c=='?'){
        ret[max(j,k)]+=a[j]*b[k];
        ret[max(j,k)]%=MOD;
      }
      if(c=='e'||c=='?'){
        ret[mex(j,k)]+=a[j]*b[k];
        ret[mex(j,k)]%=MOD;
      }
    }
  }
  return ret;
}

int main(){
  string S;
  int K;
  cin>>S>>K;
  int N=S.size();
  int i=0;
  vector<ll> ans=dfs(S,i);
  cout<<ans[K]<<'\n';
}
0