結果

問題 No.1677 mæx
ユーザー SSRSSSRS
提出日時 2021-09-10 21:39:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 172,736 KB
実行使用メモリ 10,584 KB
最終ジャッジ日時 2023-09-02 16:21:54
合計ジャッジ時間 3,075 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 18 ms
8,196 KB
testcase_05 AC 17 ms
8,220 KB
testcase_06 AC 18 ms
8,208 KB
testcase_07 AC 18 ms
8,236 KB
testcase_08 AC 18 ms
8,256 KB
testcase_09 AC 18 ms
8,416 KB
testcase_10 AC 19 ms
8,368 KB
testcase_11 AC 18 ms
8,420 KB
testcase_12 AC 18 ms
8,368 KB
testcase_13 AC 18 ms
8,200 KB
testcase_14 AC 18 ms
8,300 KB
testcase_15 AC 18 ms
8,288 KB
testcase_16 AC 17 ms
8,184 KB
testcase_17 AC 17 ms
8,248 KB
testcase_18 AC 16 ms
8,332 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 18 ms
10,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
vector<vector<int>> mex = {{1, 2, 1}, {2, 0, 0}, {1, 0, 0}};
vector<long long> eval(string &S, int &p){
  if (S[p] == '0'){
    p++;
    return {1, 0, 0};
  } else if (S[p] == '1'){
    p++;
    return {0, 1, 0};
  } else if (S[p] == '2'){
    p++;
    return {0, 0, 1};
  } else if (S[p] == '?'){
    p++;
    return {1, 1, 1};
  } else {
    string op = S.substr(p, 3);
    vector<long long> ans(3, 0);
    p += 4;
    vector<long long> A = eval(S, p);
    p++;
    vector<long long> B = eval(S, p);
    p++;
    for (int i = 0; i < 3; i++){
      for (int j = 0; j < 3; j++){
        if (op != "mex"){
          ans[max(i, j)] += A[i] * B[j];
          ans[max(i, j)] %= MOD;
        }
        if (op != "max"){
          ans[mex[i][j]] += A[i] * B[j];
          ans[mex[i][j]] %= MOD;
        }
      }
    }
    return ans;
  }
}
int main(){
  string S;
  cin >> S;
  int K;
  cin >> K;
  int p = 0;
  vector<long long> ans = eval(S, p);
  cout << ans[K] << endl;
}
0