結果

問題 No.1677 mæx
ユーザー beetbeet
提出日時 2021-09-10 22:45:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,220 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 70,664 KB
実行使用メモリ 814,244 KB
最終ジャッジ日時 2023-09-02 19:47:54
合計ジャッジ時間 2,595 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
using namespace std;

const int MOD = 998244353;
const int MAX = 2e5+10;
int ans[3][MAX]={};

int mex(int i,int j){
  if(i!=0 and j!=0) return 0;
  if(i!=1 and j!=1) return 1;
  return 2;
}

void number(string s,int& p){
  if(isdigit(s[p])){
    ans[s[p]-'0'][p]=1;
  }else{
    assert(s[p]=='?');
    ans[0][p]=ans[1][p]=ans[2][p]=1;
  }
  p++;
}

void expression(string s,int& p){
  if(s[p]!='m'){
    number(s,p);
    return;
  }

  int x=p;
  assert(s[p]=='m' and s[p+2]=='x' and s[p+3]=='(');
  char c=s[p+1];
  assert(c=='a' or c=='e' or c=='?');
  p+=4;

  int y=p;
  expression(s,p);
  assert(s[p]==',');
  p+=1;

  int z=p;
  expression(s,p);
  assert(s[p]==')');
  p+=1;

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(c=='a' or c=='?'){
        ans[max(i,j)][x]+=1ULL*ans[i][y]*ans[j][z]%MOD;
        ans[max(i,j)][x]%=MOD;
      }
      if(c=='e' or c=='?'){
        ans[mex(i,j)][x]+=1ULL*ans[i][y]*ans[j][z]%MOD;
        ans[mex(i,j)][x]%=MOD;
      }
    }
  }
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  string s;
  cin>>s;

  int p=0;
  expression(s,p);

  int k;
  cin>>k;
  cout<<ans[k][0]<<endl;

  return 0;
}
0