結果

問題 No.1677 mæx
ユーザー umncumnc
提出日時 2021-09-22 17:26:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,862 bytes
コンパイル時間 8,466 ms
コンパイル使用メモリ 134,036 KB
実行使用メモリ 8,012 KB
最終ジャッジ日時 2023-09-18 18:26:10
合計ジャッジ時間 13,627 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 10 ms
6,512 KB
testcase_05 AC 10 ms
6,572 KB
testcase_06 AC 10 ms
6,552 KB
testcase_07 AC 10 ms
6,536 KB
testcase_08 AC 10 ms
6,616 KB
testcase_09 AC 10 ms
6,540 KB
testcase_10 AC 10 ms
6,524 KB
testcase_11 AC 10 ms
6,560 KB
testcase_12 AC 10 ms
6,532 KB
testcase_13 AC 10 ms
6,504 KB
testcase_14 AC 10 ms
6,608 KB
testcase_15 AC 10 ms
6,584 KB
testcase_16 AC 10 ms
6,504 KB
testcase_17 AC 10 ms
6,576 KB
testcase_18 AC 10 ms
6,604 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 11 ms
8,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define reps(i, s, e) for (ll i = s; i <= e; ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using ld = long double;
using cp = complex<ld>;
using pa = pair<ll, ll>;
using tup = tuple<ll, ll, ll>;
using vp = vector<pair<ll, ll>>;
using vtup = vector<tuple<ll, ll, ll>>;
using st = string;
using vs = vector<string>;
using vc = vector<char>;
using vvi = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vi = vector<ll>;
const ll MOD1 = 1000000007;
const ll MOD2 = 998244353;
const ll INF = (1LL << 60);

int mex[3][3];

array<ll, 3> f(int &i, string &s) {
  // 0, 1, 2 の場合
  if (s[i] != 'm') {
    array<ll, 3> res = {};
    if (isdigit(s[i])) {
      res[s[i] - '0'] = 1;
    } else {
      res[0] = res[1] = res[2] = 1;
    }
    i++;
    return res;
  }

  // m?x(a,b)の場合
  st m = s.substr(i, 3);
  i += 3;    // "m?x"
  int type;  // 1:max, 2:mex, 3:m?x
  if (m == "max") {
    type = 1;
  } else if (m == "mex") {
    type = 2;
  } else {
    type = 3;
  }
  i++;  // "("
  array<ll, 3> a = f(i, s);
  i++;  // ","
  array<ll, 3> b = f(i, s);
  i++;  // ")"
  array<ll, 3> res = {};
  // max
  if (type & 1) {
    rep(i, 3) rep(j, 3) {
      res[max(i, j)] += a[i] * b[j];
      res[max(i, j)] %= MOD2;
    }
  }

  // mex
  if (type & 2) {
    rep(i, 3) rep(j, 3) {
      res[mex[i][j]] += a[i] * b[j];
      res[mex[i][j]] %= MOD2;
    }
  }
  return res;
}

int main() {
  mex[0][0] = 1;
  mex[0][1] = 2;
  mex[0][2] = 1;
  mex[1][0] = 2;
  mex[1][1] = 0;
  mex[1][2] = 0;
  mex[2][0] = 1;
  mex[2][1] = 0;
  mex[2][2] = 0;

  st s;
  ll k;
  cin >> s >> k;

  int i = 0;
  array<ll, 3> a = f(i, s);
  cout << a[k] << endl;
}
0