結果

問題 No.1677 mæx
ユーザー ripityripity
提出日時 2022-11-15 23:18:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 4,712 ms
コンパイル使用メモリ 267,524 KB
実行使用メモリ 13,084 KB
最終ジャッジ日時 2023-10-16 22:09:04
合計ジャッジ時間 6,704 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 18 ms
9,924 KB
testcase_05 AC 17 ms
9,964 KB
testcase_06 AC 18 ms
9,940 KB
testcase_07 AC 17 ms
9,912 KB
testcase_08 AC 17 ms
9,952 KB
testcase_09 AC 18 ms
10,000 KB
testcase_10 AC 18 ms
9,940 KB
testcase_11 AC 17 ms
10,012 KB
testcase_12 AC 18 ms
9,948 KB
testcase_13 AC 17 ms
9,896 KB
testcase_14 AC 18 ms
10,020 KB
testcase_15 AC 17 ms
9,996 KB
testcase_16 AC 17 ms
9,916 KB
testcase_17 AC 17 ms
9,952 KB
testcase_18 AC 18 ms
10,028 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 20 ms
13,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
int mex(int x, int y) {
  if( x > y ) swap(x, y);
  if( x == 0 ) {
    if( y == 1 ) {
      return 2;
    }else {
      return 1;
    }
  }else {
    return 0;
  }
}
bool isnumber(char c) {
  return ( c == '?' || isdigit(c) );
}
vector<mint> number(string& S, int& i) {
  vector<mint> dp(3);
  for( int j = 0; j < 3; j++ ) {
    if( S[i] == '?' || S[i]-'0' == j ) dp[j]++;
  }
  i += 1;
  return dp;
}
vector<mint> expression(string& S, int& i) {
  vector<mint> dp(3), lp(3), rp(3);
  if( isnumber(S[i]) ) {
    return number(S, i);
  }else {
    char op = S[i+1];
    i += 4;
    lp = expression(S, i);
    i += 1;
    rp = expression(S, i);
    for( int j = 0; j < 3; j++ ) {
      for( int k = 0; k < 3; k++ ) {
        if( op != 'e' ) dp[max(j, k)] += lp[j]*rp[k];
        if( op != 'a' ) dp[mex(j, k)] += lp[j]*rp[k];
      }
    }
  }
  i += 1;
  return dp;
} 
int main() {
  int K, i = 0;
  string S;
  cin >> S >> K;
  cout << expression(S, i)[K].val() << endl;
}
0