結果

問題 No.1677 mæx
ユーザー kwm_tkwm_t
提出日時 2021-09-10 23:17:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,088 bytes
コンパイル時間 3,843 ms
コンパイル使用メモリ 231,680 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-06-12 03:55:11
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

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