結果

問題 No.1677 mæx
ユーザー kwm_tkwm_t
提出日時 2021-09-10 23:17:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,088 bytes
コンパイル時間 3,763 ms
コンパイル使用メモリ 229,484 KB
実行使用メモリ 9,468 KB
最終ジャッジ日時 2023-09-02 21:40:08
合計ジャッジ時間 7,748 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,468 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,368 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"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
string s;
int mex(int x, int y) {
	int z;
	if ((0 == x) && (0 == y))z = 1;
	if ((0 == x) && (1 == y))z = 2;
	if ((0 == x) && (2 == y))z = 1;
	if ((1 == x) && (0 == y))z = 2;
	if ((1 == x) && (1 == y))z = 0;
	if ((1 == x) && (2 == y))z = 0;
	if ((2 == x) && (0 == y))z = 1;
	if ((2 == x) && (1 == y))z = 0;
	if ((2 == x) && (2 == y))z = 0;
	return z;
}
vector<mint> dfs(int l, int r) {
	//cout << l << " " << r << endl;
	//cout << s.substr(l, r - l) << endl;;
	vector<mint>v(3);
	if ('m' == s[l]) {
		int pos = 0;
		int count = 0;
		rep2(i, l, r) {
			if (',' == s[i]) {
				if (1 == count) {
					pos = i;
					break;
				}
			}
			else if ('(' == s[i]) {
				count++;
			}
			else if (')' == s[i]) {
				count--;
			}
		}
		auto lv = dfs(l + 4, pos);
		auto rv = dfs(pos + 1, r - 1);
		if ('a' != s[l + 1]) {
			//mex
			rep(i, 3)rep(j, 3) v[mex(i, j)] += lv[i] * rv[j];
		}
		if ('e' != s[l + 1]) {
			//max
			rep(i, 3)rep(j, 3) v[max(i, j)] += lv[i] * rv[j];
		}
	}
	else {
		if ('?' == s[l]) {
			rep(i, 3)v[i]++;
		}
		else {
			v[s[l] - '0']++;
		}
	}
	return v;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> s;
	int k; cin >> k;
	auto v = dfs(0, s.size());
	cout << v[k].val()  << endl;
	return 0;
}
0