結果
| 問題 | No.1677 mæx |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-19 20:28:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,657 bytes |
| コンパイル時間 | 1,051 ms |
| コンパイル使用メモリ | 103,152 KB |
| 実行使用メモリ | 21,416 KB |
| 最終ジャッジ日時 | 2024-12-31 15:24:44 |
| 合計ジャッジ時間 | 5,564 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 WA * 12 TLE * 1 |
ソースコード
#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;
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} };
vector<tuple<long long, long long, long long>> mem(200020);
long long mod = 998244353;
tuple<long long,long long,long long> expression(int i) {
if (mem[i] != make_tuple(-1, -1, -1)) {
return mem[i];
}
int i2 = i;
if (s[i] == 'm') {
i++;
tuple<long long, long long, long long> ans = { 0, 0, 0 };
long long ans1[3] = { 0,0,0 };
int i1 = i;
if (s[i1] == 'e' || s[i1] == '?') {
tuple<long long, long long, long long> t = expression(i + 3);
if (s[i + 3] == 'm') {
i += 7;
int now = 1;
while (now != 0) {
if (s[i] == '(') {
now++;
}
if (s[i] == ')') {
now--;
}
i++;
}
}
else {
i += 2;
}
tuple<long long, long long, long long> t1 = expression(i + 1);
long long u[3] = { get<0>(t),get<1>(t),get<2>(t) };
long long u1[3] = { get<0>(t1),get<1>(t1),get<2>(t1) };
for (int k = 0; k < 3; k++) {
for (int j = 0; j < 3; j++) {
ans1[e[k][j]] += u[k] * u1[j] % mod;
ans1[e[k][j]] %= mod;
}
}
}
if (s[i1] == 'a' || s[i1] == '?') {
tuple<long long, long long, long long> t = expression(i1 + 3);
if (s[i1 + 3] == 'm') {
i1 += 7;
int now = 1;
while (now != 0) {
if (s[i1] == '(') {
now++;
}
if (s[i1] == ')') {
now--;
}
i1++;
}
}
else {
i1 += 2;
}
tuple<long long, long long, long long> t1 = expression(i1 + 1);
long long u[3] = { get<0>(t),get<1>(t),get<2>(t) };
long long u1[3] = { get<0>(t1),get<1>(t1),get<2>(t1) };
for (int k = 0; k < 3; k++) {
for (int j = 0; j < 3; j++) {
ans1[a[k][j]] += u[k] * u1[j] % mod;
ans1[a[k][j]] %= mod;
}
}
}
ans = { ans1[0],ans1[1],ans1[2] };
mem[i2] = ans;
return ans;
}
else {
if (s[i] == '0') {
mem[i2] = { 1,0,0 };
return { 1,0,0 };
}
else if (s[i] == '1') {
mem[i2] = { 0,1,0 };
return { 0,1,0 };
}
else if (s[i] == '2') {
mem[i2] = { 0,0,1 };
return { 0,0,1 };
}
else {
mem[i2] = { 1,1,1 };
return { 1,1,1 };
}
}
}
int main() {
cin >> s >> k;
for (int i = 0; i < s.size(); i++) {
mem[i] = { -1,-1,-1 };
}
tuple<long long, long long, long long> ans1 = expression(0);
long long ans[3] = { get<0>(ans1),get<1>(ans1),get<2>(ans1) };
cout << ans[k] << endl;
}