結果
| 問題 |
No.1677 mæx
|
| コンテスト | |
| ユーザー |
stoq
|
| 提出日時 | 2021-08-02 04:17:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,321 bytes |
| コンパイル時間 | 2,113 ms |
| コンパイル使用メモリ | 195,308 KB |
| 最終ジャッジ日時 | 2025-01-23 13:39:03 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); i++)
constexpr ll MOD = 998244353;
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) の場合
string 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)] %= MOD;
}
}
// mex
if (type & 2) {
rep(i, 3) rep(j, 3) {
res[mex[i][j]] += a[i] * b[j];
res[mex[i][j]] %= MOD;
}
}
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;
string s;
int k;
cin >> s >> k;
int i = 0;
array<ll, 3> a = f(i, s);
cout << a[k] << "\n";
}
stoq