結果

問題 No.1677 mæx
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-28 04:53:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,115 bytes
コンパイル時間 5,598 ms
コンパイル使用メモリ 309,312 KB
実行使用メモリ 9,304 KB
最終ジャッジ日時 2023-08-28 04:53:54
合計ジャッジ時間 10,089 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,752 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 TLE -
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<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int mex(int a,int b){
  int res=0;
  while(res==a||res==b)res++;
  return res;
}
int main(){
  sr s;int k;cin>>s>>k;
  int n=s.size();
  auto f=[&](auto f,int l,int r)->vc<mint>{
    vc<mint>res(3,0);
    if(r-l==1){
      if(s[l]=='?')rep(i,3)res[i]++;
      else res[s[l]-'0']++;
      return res;
    }
    int p=0; 
    vc<mint>ra,rb;
    for(int i=l+4;i<r;i++){
      if(s[i]=='(')p++;
      if(s[i]==')')p--;
      if(p==0&&s[i]==','){
        ra=f(f,l+4,i); rb=f(f,i+1,r-1);
        break;
      }
    }
    rep(a,3)rep(b,3){
      if(s[l+1]!='a')res[mex(a,b)]+=ra[a]*rb[b];
      if(s[l+1]!='b')res[max(a,b)]+=ra[a]*rb[b];
    }
    return res;
  };
  auto ans=f(f,0,n);
  cout<<ans[k].val();
}
0