結果

問題 No.1677 mæx
ユーザー 夜
提出日時 2021-12-15 21:00:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,362 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 91,484 KB
実行使用メモリ 9,548 KB
最終ジャッジ日時 2023-10-01 02:33:16
合計ジャッジ時間 3,040 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 16 ms
7,420 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 17 ms
7,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 18 ms
7,664 KB
testcase_15 AC 18 ms
7,504 KB
testcase_16 AC 18 ms
7,364 KB
testcase_17 AC 19 ms
7,384 KB
testcase_18 AC 18 ms
7,448 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 19 ms
9,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
string s;
int k, i = 0;
int e[3][3] = { {1,2,1},{2,0,0},{1,0,0} };
int a[3][3] = { {0,1,2},{1,1,2},{2,2,2} };
long long mod = 998244353;
typedef struct { long long x, y, z; }t;
t expression(int &i){
	if (s[i] == 'm') {
		i++;
		t ans = { 0,0,0 };
		if (s[i] == '?') {
			i += 3;
			t left = expression(i);
			i++;
			t right = expression(i);
			long long l[3] = { left.x,left.y,left.z };
			long long r[3] = { right.x,right.y,right.z };
			long long ans1[3] = { 0,0,0 };
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					ans1[e[i][j]] += l[i] * r[j] % mod;
					ans1[a[i][j]] += l[i] * r[j] % mod;
					ans1[e[i][j]] %= mod;
					ans1[a[i][j]] %= mod;
				}
			}
			ans.x += ans1[0], ans.y += ans1[1], ans.z += ans1[2];
		}
		else if (s[i] == 'e') {
			i += 3;
			t left = expression(i);
			i++;
			t right = expression(i);
			long long l[3] = { left.x,left.y,left.z };
			long long r[3] = { right.x,right.y,right.z };
			long long ans1[3] = { 0,0,0 };
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					ans1[a[i][j]] += l[i] * r[j] % mod;
					ans1[a[i][j]] %= mod;
				}
			}
			ans.x += ans1[0], ans.y += ans1[1], ans.z += ans1[2];
		}
		else if (s[i] == 'a') {
			i += 3;
			t left = expression(i);
			i++;
			t right = expression(i);
			long long l[3] = { left.x,left.y,left.z };
			long long r[3] = { right.x,right.y,right.z };
			long long ans1[3] = { 0,0,0 };
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					ans1[a[i][j]] += l[i] * r[j] % mod;
					ans1[a[i][j]] %= mod;
				}
			}
			ans.x += ans1[0], ans.y += ans1[1], ans.z += ans1[2];
		}
		i++;
		return { ans.x % mod,ans.y % mod,ans.z % mod };
	}
	else {
		if (s[i] == '0') {
			i++;
			return { 1,0,0 };
		}
		else if (s[i] == '1') {
			i++;
			return { 0,1,0 };
		}
		else if (s[i] == '2') {
			i++;
			return { 0,0,1 };
		}
		else {
			i++;
			return { 1,1,1 };
		}
	}
}
int main() {
	cin >> s >> k;
	t ans = expression(i);
	if (k == 0)cout << ans.x <<endl;
	if (k == 1)cout << ans.y << endl;
	if (k == 2)cout << ans.z << endl;
	return 0;
}
0